Is std::container::size_type guaranteed to be size_t for standard containers with default allocator?
问题 Like: std::string<T>::size_type std::list<T>::size_type std::map<T>::size_type std::vector<T>::size_type etc. Both cplusplus.com and cppreference.com say that they are usually size_t , but are they truly, unambiguously guaranteed by the standard to be size_t unless a custom allocator is used? 回答1: For STL-containers - nope. Table 96 of the standard in [container.requirements.general], which lists container requirements for any container X , explains it pretty clear: However, for basic_string