...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
RandomAccessIterator
A random access iterator is an iterator that can read through a sequence of values. It can move in either direction through the sequence (by any amount in constant time), and can be either mutable (data pointed to by it can be changed) or not mutable.
An iterator represents a position in a sequence. Therefore, the iterator can point into the sequence (returning a value when dereferenced and being incrementable), or be off-the-end (and not dereferenceable or incrementable).
value_type
std::iterator_traits<Iter>::value_type
The value type of the iterator
category
std::iterator_traits<Iter>::iterator_category
The category of the iterator
difference_type
std::iterator_traits<Iter>::difference_type
The difference type of the iterator (measure of the number of steps between two iterators)
i
, j
x
n
int_off
Name | Expression | Type | Semantics |
---|---|---|---|
Motion |
i += n |
Iter & |
Equivalent to applying |
Motion (with integer offset) |
i += int_off |
Iter & |
Equivalent to applying |
Subtractive motion |
i -= n |
Iter & |
Equivalent to |
Subtractive motion (with integer offset) |
i -= int_off |
Iter & |
Equivalent to |
Addition |
i + n |
Iter |
Equivalent to |
Addition with integer |
i + int_off |
Iter |
Equivalent to |
Addition (count first) |
n + i |
Iter |
Equivalent to |
Addition with integer (count first) |
int_off + i |
Iter |
Equivalent to |
Subtraction |
i - n |
Iter |
Equivalent to |
Subtraction with integer |
i - int_off |
Iter |
Equivalent to |
Distance |
i - j |
difference_type |
The number of times |
Element access |
i[n] |
const-if-not-mutable value_type & |
Equivalent to |
Element access with integer index |
i[int_off] |
const-if-not-mutable value_type & |
Equivalent to |
Copyright © 2001, 2002 Indiana University Copyright © 2000, 2001 University of Notre Dame du Lac Copyright © 2000 Jeremy Siek, Lie-Quan Lee, Andrew Lumsdaine Copyright © 1996-1999 Silicon Graphics Computer Systems, Inc. Copyright © 1994 Hewlett-Packard Company |