A RandomAccessIterator is a BidirectionalIterator that can be moved to point to any element in constant time.
A pointer to an element of an array satisfies all requirements of RandomAccessIterator.
Requirements
The type It satisfies RandomAccessIterator if.
- The type
ItsatisfiesBidirectionalIterator
And, given.
-
value_type, the type denoted bystd::iterator_traits<It>::value_type -
difference_type, the type denoted bystd::iterator_traits<It>::difference_type -
reference, the type denoted bystd::iterator_traits<It>::reference -
i,a,b, objects of typeItorconst It -
r, a value of typeIt& -
n, an integer of typedifference_type
The following expressions must be valid and have their specified effects.
| Expression | Return type | Operational semantics | Notes |
|---|---|---|---|
r += n | It& | difference_type m = n; if (m >= 0) while (m--) ++r; else while (m++) --r; return r; |
|
a + n
| It | It temp = a; return temp += n; |
|
r -= n | It& | return r += -n; | |
i - n | It | It temp = i; return temp -= n; | |
b - a | difference_type | return n; | Precondition:
Postcondition:
|
i[n] | convertible to reference | *(i + n) | |
a < b | contextually convertible to bool | b - a > 0 | Strict total ordering relation:
|
a > b | contextually convertible to bool | b < a | Total ordering relation opposite to a < b |
a >= b | contextually convertible to bool | !(a < b) | |
a <= b | contextually convertible to bool | !(a > b) |
The above rules imply that RandomAccessIterator also implements LessThanComparable.
A mutable RandomAccessIterator is a RandomAccessIterator that additionally satisfies the OutputIterator requirements.
Please login to continue.