...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
A Random Access Iterator is a Bidirectional Iterator that provides constant-time methods for moving forward and backward on a sequence in arbitrary-sized steps.
Random Access Iterator defines two new expressions and refines the ones described in Bidirectional Iterator.
Expression | Expression type |
---|---|
typename i::next | A model of Random Access Iterator |
typename i::prior | A model of Random Access Iterator |
typename i::template advance<n>::type | A model of Random Access Iterator |
typename i::template distance<j>::type | A model of Integral Constant |
Semantics of an expression is defined only where it is not defined in Bidirectional Iterator.
Expression | Complexity | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typename i::template advance<n>::type | Amortized constant time | Including i itself, there must be n::value dereferenceable or past-the-end iterators following or preceding i , depending on whether n is positive or negative. | If n::value > 0 , equivalent to executing i::next n::value times; if n::value < 0 , equivalent to executing i::prior n::value times; if n::value == 0 , this is a null operation [1]. | The resulting iterator is dereferenceable or past-the-end. |
typename i::template distance<j>::type | Amortized constant time | Either i is reachable from j or j is reachable from i , or both. | Returns an integral constant n such that i::template advance<n>::type is identical to j . |
For any random access iterators i
and j
the following invariants always hold:
i::advance<n>::type
is well-defined, then i::advance<n>::type::advance< negate<n>::type >::type
is a null operation.
Random Access Sequence, Bidirectional Iterator