簡體   English   中英

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

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

標准沒有說明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;
                                                 ^

這是GCC的錯誤嗎? 還是我誤讀標准?

  • GCC版本:4.9.2

不,這是不允許的。 表99的第一行:

表99

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM