Difference between revisions of "cpp/named req/RandomAccessIterator"
(Added LWG issue #1079 DR.) |
(LWG2114/P2167R3) |
||
(One intermediate revision by one user not shown) | |||
Line 58: | Line 58: | ||
|{{c|i[n]}}||convertible to {{tt|reference}}||{{c|*(i + n)}}|| | |{{c|i[n]}}||convertible to {{tt|reference}}||{{c|*(i + n)}}|| | ||
|- | |- | ||
− | |{{c|a < b}}|| | + | |{{c|a < b}} |
+ | |{{rrev multi|noborder=true | ||
+ | |rev1=meets {{named req|BooleanTestable}} | ||
+ | |since2=c++20|rev2=models {{lconcept|boolean-testable}} | ||
+ | }} | ||
+ | |Equivalent to {{c|return b - a > 0;}} | ||
|Precondition: | |Precondition: | ||
* same as of {{c|b - a}}<!-- LWG3236 --> | * same as of {{c|b - a}}<!-- LWG3236 --> | ||
Line 67: | Line 72: | ||
* {{c|a < b}} or {{c|b < a}} or {{c|1=a == b}}<br> (exactly one of the expressions is true) | * {{c|a < b}} or {{c|b < a}} or {{c|1=a == b}}<br> (exactly one of the expressions is true) | ||
|- | |- | ||
− | |{{c|a > b}}|| | + | |{{c|a > b}} |
+ | |{{rrev multi|noborder=true | ||
+ | |rev1=meets {{named req|BooleanTestable}} | ||
+ | |since2=c++20|rev2=models {{lconcept|boolean-testable}} | ||
+ | }} | ||
+ | |{{c|b < a}} | ||
+ | |Total ordering relation opposite to {{c|a < b}} | ||
|- | |- | ||
− | |{{c|1=a >= b}}|| | + | |{{c|1=a >= b}} |
+ | |{{rrev multi|noborder=true | ||
+ | |rev1=meets {{named req|BooleanTestable}} | ||
+ | |since2=c++20|rev2=models {{lconcept|boolean-testable}} | ||
+ | }} | ||
+ | |{{c|!(a < b)}} | ||
+ | | | ||
|- | |- | ||
− | |{{c|1=a <= b}}|| | + | |{{c|1=a <= b}} |
+ | |{{rrev multi|noborder=true | ||
+ | |rev1=meets {{named req|BooleanTestable}} | ||
+ | |since2=c++20|rev2=models {{lconcept|boolean-testable}} | ||
+ | }} | ||
+ | |{{c|!(a > b)}} | ||
+ | | | ||
|} | |} | ||
Line 100: | Line 123: | ||
{{dcl end}} | {{dcl end}} | ||
− | where the exposition-only concept {{tt|__LegacyBidirectionalIterator}} is described in {{rlp|BidirectionalIterator#Concept|LegacyBidirectionalIterator | + | where the exposition-only concept {{tt|__LegacyBidirectionalIterator}} is described in {{rlp|BidirectionalIterator#Concept|LegacyBidirectionalIterator}}. |
}} | }} | ||
Line 108: | Line 131: | ||
{{dr list item|wg=lwg|dr=448|std=C++98|before=the return type of {{c|a[n]}} was required<br>to be convertible to {{tt|value_type}}|after=the return type is required to be<br>convertible to {{c/core|const value_type&}}<ref>{{lwg|299}} was reopened after this resolution.</ref>}} | {{dr list item|wg=lwg|dr=448|std=C++98|before=the return type of {{c|a[n]}} was required<br>to be convertible to {{tt|value_type}}|after=the return type is required to be<br>convertible to {{c/core|const value_type&}}<ref>{{lwg|299}} was reopened after this resolution.</ref>}} | ||
{{dr list item|wg=lwg|dr=1079|std=C++98|before={{c|b - a}} was defined using {{c|a < b}},<br>resulted in circular definition|after=removed {{c|a < b}} from the definition}} | {{dr list item|wg=lwg|dr=1079|std=C++98|before={{c|b - a}} was defined using {{c|a < b}},<br>resulted in circular definition|after=removed {{c|a < b}} from the definition}} | ||
+ | {{dr list item|wg=lwg|dr=2114|paper=P2167R3|std=C++98|before=convertibility to {{c/core|bool}} was too weak to reflect the expectation of implementations|after=requirements strengthened}} | ||
{{dr list end}} | {{dr list end}} | ||
<references/> | <references/> |
Latest revision as of 19:46, 8 September 2024
A LegacyRandomAccessIterator is a LegacyBidirectionalIterator that can be moved to point to any element in constant time.
If a LegacyRandomAccessIterator it originates from a Container, then it's value_type
is the same as the container's, so dereferencing (*it) obtains the container's value_type
.
A pointer to an element of an array satisfies all requirements of LegacyRandomAccessIterator.
Contents |
[edit] 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 type
It
or const It - r, an lvalue of type
It
- n, an integer of type
difference_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; (see the precondition) |
Precondition:
Postcondition:
| ||||
i[n] | convertible to reference |
*(i + n) | |||||
a < b |
|
Equivalent to return b - a > 0; | Precondition:
Strict total ordering relation:
| ||||
a > b |
|
b < a | Total ordering relation opposite to a < b | ||||
a >= b |
|
!(a < b) | |||||
a <= b |
|
!(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) |
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 299 (N3066) |
C++98 | the return type of a[n] was required to be convertible to const value_type& |
the return type is required to be convertible to reference
|
LWG 448 | C++98 | the return type of a[n] was required to be convertible to value_type
|
the return type is required to be convertible to const value_type&[1] |
LWG 1079 | C++98 | b - a was defined using a < b, resulted in circular definition |
removed a < b from the definition |
LWG 2114 (P2167R3) |
C++98 | convertibility to bool was too weak to reflect the expectation of implementations | requirements strengthened |
- ↑ LWG issue 299 was reopened after this resolution.
[edit] See also
(C++20) |
specifies that a bidirectional_iterator is a random-access iterator, supporting advancement in constant time and subscripting (concept) |
Iterator library | provides definitions for iterators, iterator traits, adaptors, and utility functions |