Is there is a difference between size_t
and container::size_type
?
What I understand is size_t
is more generic and can be used for any size_type
s.
But is container::size_type
optimized for specific kinds of containers?
ccontainer-data-typesize-type
Is there is a difference between size_t
and container::size_type
?
What I understand is size_t
is more generic and can be used for any size_type
s.
But is container::size_type
optimized for specific kinds of containers?
Best Answer
The standard containers define
size_type
as a typedef toAllocator::size_type
(Allocator is a template parameter), which forstd::allocator<T>::size_type
is typically defined to besize_t
(or a compatible type). So for the standard case, they are the same.However, if you use a custom allocator a different underlying type could be used. So
container::size_type
is preferable for maximum generality.