'size_t'vs'container :: size_type' [英] 'size_t' vs 'container::size_type'
问题描述
size_t
和 container :: size_type
之间有区别吗?
我理解的是 size_t
更通用,可以用于任何 size_type
。
但是 container :: size_type
是针对特定种类的容器优化的吗?
<标准容器定义
size_type
作为的分类器Allocator :: size_type code>(Allocator是一个模板参数),它为 std :: allocator
定义为 size_t
。因此,对于标准情况,它们是相同的。
但是,如果使用自定义分配器,可以使用不同的底层类型。因此, container :: size_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?
解决方案 The standard containers define size_type
as a typedef to Allocator::size_type
(Allocator is a template parameter), which for std::allocator
is defined to be size_t
. 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.
这篇关于'size_t'vs'container :: size_type'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!