C++容器:容器中衍生出的类型

本文详细介绍了容器类型中的size_type、iterator、const_iterator、reverse_iterator、difference_type、value_type、reference及const_reference等概念,并解释了它们在容器操作中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 容器中衍生出的类型:

size_type

Unsigned integral type large enough to hold size of largest possible container of this container type

无符号整型,足以存储此容器类型的最大可能容器长度

iterator

Type of the iterator for this container type

此容器类型的迭代器类型

const_iterator

Type of the iterator that can read but not write the elements

元素的只读迭代器类型

reverse_iterator

Iterator that addresses elements in reverse order

按逆序寻址元素的迭代器

const_reverse_iterator

Reverse iterator that can read but not write the elements

元素的只读(不能写)逆序迭代器

difference_type

Signed integral type large enough to hold the difference, which might be negative, between two iterators

足够存储两个迭代器差值的有符号整型,可为负数

value_type

Element type

元素类型

reference

Element's lvalue type; synonym for value_type&

元素的左值类型,是 value_type& 的同义词

const_reference

Element's const lvalue type; same as const value_type&

元素的常量左值类型,等效于 const value_type&

 

value_type + reference + const_reference 的特殊点:

1.无须直接知道容器元素的真正类型,就能使用它。需要使用元素类型时,只要用 value_type 即可。

2.如果要引用该类型,则通过 referenceconst_reference 类型实现。

在程序员编写自己的泛型程序时,这些元素相关类型的定义非常有用。

猜测:reference和void * 类似。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值