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?
No, it's not allowed. First row of table 99:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With