Next : , Previous : Bidirectional iterators, Top : Table of Contents


Random access iterators

+= Operator on random access iterators
+ Operator on random access iterators
-= Operator on random access iterators
- Operator on random access iterators
[n] Operator on random access iterators
< Operator on random access iterators
> Operator on random access iterators
<= Operator on random access iterators
>= Operator on random access iterators

A class or a built-in type X satisfies the requirements of a random access iterator if the following lines are added to the table that specifies bidirectional iterators:

Table 6: Random access iterator requirements (in addition to bidirectional iterator)

Expression Return type Operational semantics Assertion/note pre/post-condition
r += n X&
{ Distance m = n;
  if (m >= 0)
    while (m--) ++r;
  else
    while (m++) --r;
  return r; }
a + n
n + a
X
{ X tmp = a;
  return tmp += n; }
a + n == n + a.
r -= n X& return r += -n;
a - n X
{ X tmp = a;
  return tmp -= n; }
b - a Distance pre: there exists a value n of Distance such that a + n = b.
b == a + (b - a).

a[n] convertible to T *(a + n)
a < b convertible to bool b - a > 0 < is a total ordering relation
a > b convertible to bool b < a > is a total ordering relation opposite to <.
a >= b convertible to bool !(a < b)
a <= b convertible to bool !(a > b)


 

Top