std::Random Access Iterator
<iterator>
Random-access iterator category
Random access iterators are iterators especially designed for having the same functionality as standard pointers. Pointers
are random access iterators.
Random access iterators are the most complete iterators in terms of functionality.
There is not a single type of
random access iterator: Each container defines its own specific iterator type able to iterate through it and access its elements. But all
random access iterators support -at least- the following operations:
| characteristic | valid expressions |
| Can be default-constructed | X a;
X() |
| Can be copied and copy-constructed | X b(a);
b = a; |
Accepts equality/inequality comparisons.
Equal iterators imply the same element is pointed | a == b
a != b |
| Can be dereferenced (when not null) | *a
a->m |
| Can be incremented and decremented (when not null) | ++a
--a
a++
a-- |
| Supports arithmetic operators + and - between an iterator and an integer value, or subtracting an iterator from another | 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] |
Where
X is an iterator type,
a and
b are objects of this iterator type, and
n is an integral type.
See also
- Input Iterator
- Input iterator category
- Output Iterator
- Output iterator category
- Forward Iterator
- Forward iterator category
- Bidirectional Iterator
- Bidirectional iterator category
- iterator
- Iterator base class (class template
)