喜欢:
-
std::string<T>::size_type
-
std::list<T>::size_type
-
std::map<T>::size_type
-
std::vector<T>::size_type
- 等等
两者都是cplusplus.com和 cppreference.com说他们通常是size_t
,但它们是否真正、明确地保证为 size_t
的标准除非使用自定义分配器?
最佳答案
对于 STL 容器 - 不。 [container.requirements.general] 中标准的表 96,其中列出了任何容器的容器要求 X
,解释得很清楚:
但是,对于 basic_string
, size_type
定义为
typedef typename allocator_traits<Allocator>::size_type size_type;
这又将是 size_t
对于 std::allocator<..>
作为分配器。
此外,std::array
使用 size_t
作为size_type
,根据 [array.overview]/3。
关于c++ - 对于具有默认分配器的标准容器,std::container::size_type 是否保证为 size_t?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26433802/