C++ Library - <iterator>



Introduction

It is a pointer-like object that can be incremented with ++, dereferenced with *, and compared against another iterator with !=

Categories

categorypropertiesvalid expressions
all categoriescopy-constructible, copy-assignable and destructible

X b(a);

b = a;

It can be incremented

++a

a++

Random AccessBidirectionalForwardInputIt 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
1advance

It advances the iterator it by n element positions.

2distance

It returns distance between iterators.

3begin

It is used to begin an iterator.

4end

It is used to end an iterator.

5prev

It is used to get iterator to previous element.

6next

It is used to get iterator to next element.

Iterator generators

Sr.No.Iterator generators & Description
1back_inserter

It constructs back insert iterator.

2inserter

It constructs insert iterator

3make_move_iterator

It construct move iterators.

Classes

Sr.No.Classes & Description
1iterator

It iterators base class.

2iterator_traits

It is an iterator traits.

Predefined iterators

Sr.No.Predefined iterators & Description
1reverse_iterator

It is a reverse iterator.

2move_iterator

It is a move iterator.

3back_insert_iterator

It is a back insert iterator.

4front_insert_iterator

It is a front insert iterator.

5insert_iterator

It is used to insert an iterator.

6istream_iterator

It is an input stream iterator.

7ostream_iterator

It is an output stream iterator.

8istreambuf_iterator

It is an input stream buffer iterator.

7ostreambuf_iterator

It is an output stream buffer iterator.

Category tags

Sr.No.Category tags & Description
1input_iterator_tag

Input iterator category.

2output_iterator_tag

output iterator category.

3forward_iterator_tag

Forward iterator category.

4bidirectional_iterator_tag

Bidirectional iterator category.

5random_access_iterator_tag

Random-access iterator category.