2.9 KiB
2.9 KiB
[random.access.iterators]
24 Iterators library [iterators]
24.3 Iterator requirements [iterator.requirements]
24.3.5 C++17 iterator requirements [iterator.cpp17]
24.3.5.7 Random access iterators [random.access.iterators]
A class or pointer typeX meets the requirements of a random access iterator if, in addition to meeting the Cpp17BidirectionalIterator requirements, the following expressions are valid as shown in Table 83.
Table 83 — Cpp17RandomAccessIterator requirements (in addition to Cpp17BidirectionalIterator) [tab:randomaccessiterator]
| ð Expression |
Return type | Operational | Assertion/note |
|---|---|---|---|
| ð | semantics | pre-/post-condition | |
| ð r += n |
X& | { difference_type 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; | Preconditions: the absolute value of n is in the range of representable values of difference_type. |
| ð a - n |
X | { X tmp = a; return tmp -= n; } | |
| ð b - a |
difference_type | return n; | Preconditions: there exists a value n of type difference_type such that a + n == b. b == a + (b - a). |
| ð a[n] |
convertible to reference | *(a + n) | |
| ð a < b |
decltype(a < b) models boolean-testable | Effects: Equivalent to: return b - a > 0; | < is a total ordering relation |
| ð a > b |
decltype(a > b) models boolean-testable | b < a | > is a total ordering relation opposite to <. |
| ð a >= b |
decltype(a >= b) models boolean-testable | !(a < b) | |
| ð a <= b |
decltype(a <= b) models boolean-testable | !(a > b) |