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_types.
But is container::size_type optimized for specific kinds of containers?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The standard containers define
size_typeas a typedef toAllocator::size_type(Allocator is a template parameter), which forstd::allocator<T>::size_typeis 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_typeis preferable for maximum generality.