Cpp Standard Library 简明教程
C++ Library - <iterator>
Introduction
这是一个指针状对象,可以使用++增量,使用*解引用,并可以使用!=与另一个迭代器比较。
It is a pointer-like object that can be incremented with ++, dereferenced with *, and compared against another iterator with !=
Categories
category |
properties |
valid expressions |
all categories |
copy-constructible, copy-assignable and destructible |
X b(a); b = a; |
It can be incremented |
a a |
Random Access |
Bidirectional |
Forward |
Input |
It supports equality/inequality comparisons |
a == b a != b |
It can be dereferenced as an rvalue |
*a a→m |
Output |
It 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 |
{ b = a; *a++; *b; } |
It can be decremented |
--a a-- *a-- |
|
It supports arithmetic operators + and - |
a + n n + a a - n a - b |
|
It supports inequality comparisons ( <, >, ⇐ and >=) between iterators |
a < b a > b a ⇐ b a >= b |
It supports compound assignment operations += and -= |
a += n a -= n |
It supports offset dereference operator ([]) |
a[n] |
Functions
Sr.No. |
Functions & Description |
1 |
advanceIt advances the iterator it by n element positions. |
2 |
distanceIt returns distance between iterators. |
3 |
beginIt is used to begin an iterator. |
4 |
endIt is used to end an iterator. |
5 |
prev It is used to get iterator to previous element. |
6 |
nextIt is used to get iterator to next element. |
Iterator generators
Sr.No. |
Iterator generators & Description |
1 |
back_inserterIt constructs back insert iterator. |
2 |
inserterIt constructs insert iterator |
3 |
make_move_iterator It construct move iterators. |
Classes
Sr.No. |
Classes & Description |
1 |
iteratorIt iterators base class. |
2 |
iterator_traitsIt is an iterator traits. |
Predefined iterators
Sr.No. |
Predefined iterators & Description |
1 |
reverse_iteratorIt is a reverse iterator. |
2 |
move_iteratorIt is a move iterator. |
3 |
back_insert_iteratorIt is a back insert iterator. |
4 |
front_insert_iteratorIt is a front insert iterator. |
5 |
insert_iteratorIt is used to insert an iterator. |
6 |
istream_iteratorIt is an input stream iterator. |
7 |
ostream_iteratorIt is an output stream iterator. |
8 |
istreambuf_iteratorIt is an input stream buffer iterator. |
7 |
ostreambuf_iteratorIt is an output stream buffer iterator. |
Category tags
Sr.No. |
Category tags & Description |
1 |
input_iterator_tagInput iterator category. |
2 |
output_iterator_tagoutput iterator category. |
3 |
forward_iterator_tagForward iterator category. |
4 |
bidirectional_iterator_tagBidirectional iterator category. |
5 |
random_access_iterator_tagRandom-access iterator category. |