Difference between revisions of "cpp/named req/RandomAccessIterator"
m (named req/core) |
D41D8CD98F (Talk | contribs) |
||
Line 75: | Line 75: | ||
A ''mutable'' {{named req/core|RandomAccessIterator}} is a {{named req/core|RandomAccessIterator}} that additionally satisfies the {{named req|OutputIterator}} requirements. | A ''mutable'' {{named req/core|RandomAccessIterator}} is a {{named req/core|RandomAccessIterator}} that additionally satisfies the {{named req|OutputIterator}} requirements. | ||
+ | |||
+ | {{rrev | since=c++20 | | ||
+ | ===Concept=== | ||
+ | For the definition of {{lc|std::iterator_traits}}, the following exposition-only concept is defined. | ||
+ | |||
+ | {{dcl begin}} | ||
+ | {{dcl|1= | ||
+ | template<class I> | ||
+ | concept __LegacyRandomAccessIterator<!-- called cpp17-random-access-iterator in the standard --> = | ||
+ | __LegacyBidirectionalIterator<I> && std::StrictTotallyOrdered<I> && | ||
+ | requires(I i, typename std::incrementable_traits<I>::difference_type n) { | ||
+ | { i += n } -> std::Same<I&>; | ||
+ | { i -= n } -> std::Same<I&>; | ||
+ | { i + n } -> std::Same<I>; | ||
+ | { n + i } -> std::Same<I>; | ||
+ | { i - n } -> std::Same<I>; | ||
+ | { i - i } -> std::Same<decltype(n)>; | ||
+ | { i[n] } -> std::iter_reference_t<I>; | ||
+ | }; | ||
+ | }} | ||
+ | {{dcl end}} | ||
+ | |||
+ | where the exposition-only concept {{tt|__LegacyBidirectionalIterator}} is described in {{rlp|BidirectionalIterator#Concept|LegacyBidirectionalIterator#Concept}}. | ||
+ | }} | ||
===See also=== | ===See also=== |
Revision as of 07:27, 16 March 2019
A LegacyRandomAccessIterator 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 LegacyRandomAccessIterator
Requirements
The type It
satisfies LegacyRandomAccessIterator 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 LegacyRandomAccessIterator also implements LessThanComparable.
A mutable LegacyRandomAccessIterator is a LegacyRandomAccessIterator that additionally satisfies the LegacyOutputIterator requirements.
ConceptFor the definition of std::iterator_traits, the following exposition-only concept is defined.
where the exposition-only concept |
(since C++20) |
See also
specifies that a BidirectionalIterator is a random-access iterator, supporting advancement in constant time and subscripting (concept) |