标准并未涉及到
我认为
但是,如果给出
std::vector
的分配器,只要求分配器满足Allocator
概念。没有关于分配器的value_type、reference_type等任何说明。我认为
std::vector<T, A>
会将A
内部重新绑定为一个用于T
的分配器,因此我给了一个使用std::allocator<char>
的向量,并且它按预期工作。但是,如果给出
std::allocator<void>
,GCC会生成错误,如下所示:/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;
^
这是GCC的一个bug吗?还是我对标准的理解有误?
- GCC版本:4.9.2
std::allocator<void>
是无效的,因为模板参数需要是“非const对象类型”,而void
不是。 - Ben Voigtvoid
,std::allocator
存在一个明确的特化。 - T.C.allocator_traits
在使用allocator<void>
时失败了。 - Ben Voigtlibstdc++
故意支持std::vector<int,std::allocator<char>>
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64865#c3),因此我想知道在`allocator<void>`上中断是否是一个疏忽。 - T.C.