For std::[w]string , std::[w]string::size_type is equal to std::allocator<T>::size_type , which is equal to std::size_t . For other containers, this is a specific implementation defined by an unsigned integer type.
It is sometimes useful to have an exact type, so for example, one knows where the type goes around (for example, up to UINT_MAX ) so that you can use it. Or for templates where you really need to pass two identical types to function / class templates.
Often I find that I use size_t for brevity or iterators. In general code, since you usually donβt know which container instance is used by your template and what size these containers have, you will need to use Container::size_type typedef if you need to keep the size of the containers.
Johannes Schaub - litb May 28 '09 at 12:14 a.m. 2009-05-28 00:14
source share