size_t和size_type

2017-07-06  本文已影响47人  阿布554_

照个人理解,本质上没有太大区别

下面是StackOverflow的一些回答

Question: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?

Answer:The standard containers define size_type as a typedef to Allocator::size_type (Allocator is a template parameter), which for std::allocator is typically defined to be size_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 portability.

Answer2:

All std containers use size_t as the size_type, but each independent library vendor chooses a type that it finds appropriate for its container.
If you look at qt, you'll find that the size_type
of Qt containers is version dependent. In Qt3 it was unsigned int
and in Qt4 it was changed to int

上一篇下一篇

猜你喜欢

热点阅读