Difference between revisions of "cpp/named req/RandomAccessIterator"
From cppreference.com
m (T. Canens moved page cpp/concept/RandomAccessIterator to cpp/named req/RandomAccessIterator without leaving a redirect: Text replace - "cpp/concept" to "cpp/named req") |
m (Text replace - "{{concept" to "{{named req") |
||
Line 2: | Line 2: | ||
{{cpp/named req/navbar}} | {{cpp/named req/navbar}} | ||
− | A {{tt|RandomAccessIterator}} is a {{ | + | A {{tt|RandomAccessIterator}} is a {{named req|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 {{tt|RandomAccessIterator}} | A pointer to an element of an array satisfies all requirements of {{tt|RandomAccessIterator}} | ||
Line 9: | Line 9: | ||
The type {{tt|It}} satisfies {{tt|RandomAccessIterator}} if | The type {{tt|It}} satisfies {{tt|RandomAccessIterator}} if | ||
− | * The type {{tt|It}} satisfies {{ | + | * The type {{tt|It}} satisfies {{named req|BidirectionalIterator}} |
And, given | And, given | ||
Line 72: | Line 72: | ||
|} | |} | ||
− | The above rules imply that {{tt|RandomAccessIterator}} also implements {{ | + | The above rules imply that {{tt|RandomAccessIterator}} also implements {{named req|LessThanComparable}}. |
− | A {{tt|mutable RandomAccessIterator}} is a {{tt|RandomAccessIterator}} that additionally satisfies the {{ | + | A {{tt|mutable RandomAccessIterator}} is a {{tt|RandomAccessIterator}} that additionally satisfies the {{named req|OutputIterator}} requirements. |
===See also=== | ===See also=== |
Revision as of 14:13, 15 June 2018
A RandomAccessIterator
is a LegacyBidirectionalIterator 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
It
satisfies LegacyBidirectionalIterator
And, given
-
value_type
, the type denoted by std::iterator_traits<It>::value_type -
difference_type
, the type denoted by std::iterator_traits<It>::difference_type -
reference
, the type denoted by std::iterator_traits<It>::reference -
i
,a
,b
, objects of typeIt
orconst 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; |
|
a + n
n + a |
It | It temp = a; return temp += n; |
|
r -= n | It& | return r += -n; | The absolute value of n must be within the range of representable values of difference_type .
|
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 LegacyOutputIterator requirements.
See also
specifies that a BidirectionalIterator is a random-access iterator, supporting advancement in constant time and subscripting (concept) |