Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is std::vector<int, std::allocator<char> > valid?

The standard says nothing about the allocator of std::vector but only requires the allocator to satisfy the Allocator concept. Nothing about the allocator's value_type, no reference_type, no nothing.

I thought std::vector<T, A> internally rebinds A to an allocator for T, so I gave a vector std::allocator<char> and it worked as expected.

However, GCC generates errors if std::allocator<void> is given, as below:

/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/include/g++-v4/ext/alloc_traits.h: In instantiation of ‘struct __gnu_cxx::__alloc_traits<std::allocator<void> >’:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/include/g++-v4/bits/stl_vector.h:75:28:   required from ‘struct std::_Vector_base<int, std::allocator<void> >’
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/include/g++-v4/bits/stl_vector.h:214:11:   required from ‘class std::vector<int, std::allocator<void> >’
a.cpp:5:42:   required from here
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/include/g++-v4/ext/alloc_traits.h:109:53: error: forming reference to void
     typedef value_type&                             reference;
                                                 ^
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/include/g++-v4/ext/alloc_traits.h:110:53: error: forming reference to void
     typedef const value_type&                       const_reference;
                                                 ^

Is it a GCC's bug? or am I misreading the standard?

  • GCC version : 4.9.2
like image 429
Inbae Jeong Avatar asked Mar 16 '23 14:03

Inbae Jeong


1 Answers

No, it's not allowed. First row of table 99:

Table 99

like image 96
T.C. Avatar answered Mar 25 '23 05:03

T.C.