std :: vector <int,std :: allocator <char >>是否有效?

Inb*_*ong 4 c++ gcc vector allocator

标准没有说明分配器,std::vector但只需要分配器来满足这个Allocator概念.没有关于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;
                                                 ^
Run Code Online (Sandbox Code Playgroud)

这是GCC的错误吗?还是我误读标准?

  • GCC版本:4.9.2

T.C*_*.C. 7

不,这是不允许的.表99的第一行:

表99