码迷,mamicode.com
首页 > 编程语言 > 详细

C++标准库之迭代器

时间:2015-03-04 22:28:39      阅读:183      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!