首页 > 编程语言 > 详细

C++标准库之迭代器

时间:2015-03-04 22:26:55      阅读:185      评论:0      收藏:0      [点我收藏+]

迭代器是对指针进行进一步抽象的产物。

迭代器是遍历所有容器(序列)/流的统一界面,是标准库泛形算法的基础。

迭代器根据其能力分为五种:

 

categorypropertiesvalid expressions
all categories copy-constructiblecopy-assignable and destructible X b(a);
b = a;
Can be incremented ++a
a++
Random Access Bidirectional Forward Input Supports equality/inequality comparisons a == b
a != b
Can be dereferenced as an rvalue *a
a->m
Output Can be dereferenced as an lvalue 
(only for mutable iterator types)
*a = t
*a++ = t
  default-constructible X a;
X()

Multi-pass: neither dereferencing nor incrementing affects dereferenceability

Multi-pass是指,迭代器不管进行多少次自增及解引用,都不会使得其指过的对象无法访问。

{ b=a; *a++; *b; }
  Can be decremented --a
a--
*a--
  Supports arithmetic operators + and - a + n
n + a
a - n
a - b
Supports inequality comparisons (<><= and >=) between iterators a < b
a > b
a <= b
a >= b
Supports compound assignment operations += and -= a += n
a -= n
Supports offset dereference operator ([]) a[n]

C++标准库之迭代器

原文:http://www.cnblogs.com/vsuu/p/4314427.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!