2014-10-17 37 views

回答

7

對於STL容器 - 不。在[container.requirements.general]的標準,其中列出了爲任何容器X容器要求的表96,解釋它非常清楚:

enter image description here


然而,對於basic_stringsize_type被定義爲

typedef typename allocator_traits<Allocator>::size_type size_type; 

然後將size_t作爲std::allocator<..>作爲分配器。

另外,根據[array.overview]/3,std::array使用size_t作爲size_type

0

size_type不保證是size_t

但是default allocatorsize_type是,所以默認是size_t

從標準20.6.9

template <class T> class allocator { 
public: 
typedef size_t size_type; 
typedef ptrdiff_t difference_type; 
.... 

容器的SIZE_TYPE從分配器導出:

typedef typename allocator_traits<Allocator>::size_type size_type; 
+3

這僅僅是'basic_string'如此。第23條容器不保證使用分配器的'size_type'。 – 2014-10-17 21:52:34

相關問題