|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ALegacyRandomAccessIterator is aLegacyBidirectionalIterator that can be moved to point to any element in constant time.
If aLegacyRandomAccessIteratorit originates from aContainer, thenit'svalue_type is the same as the container's, so dereferencing (*it) obtains the container'svalue_type.
A pointer to an element of an array satisfies all requirements ofLegacyRandomAccessIterator.
Contents |
The typeIt satisfiesLegacyRandomAccessIterator if
It satisfiesLegacyBidirectionalIteratorAnd, given
value_type, the type denoted bystd::iterator_traits<It>::value_typedifference_type, the type denoted bystd::iterator_traits<It>::difference_typereference, the type denoted bystd::iterator_traits<It>::referenceIt orconst ItItdifference_typeThe 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 ofn must be within the range of representable values ofdifference_type. | ||||
| i- n | It | It temp= i; return temp-= n; | |||||
| b- a | difference_type | return n; (see the precondition) | Precondition:
Postcondition:
| ||||
| i[n] | convertible toreference | *(i+ n) | |||||
| a< b |
| Equivalent toreturn b- a>0; | Precondition:
Strict total ordering relation:
| ||||
| a> b |
| b< a | Total ordering relation opposite toa< b | ||||
| a>= b |
| !(a< b) | |||||
| a<= b |
| !(a> b) |
The above rules imply thatLegacyRandomAccessIterator also implementsLessThanComparable.
AmutableLegacyRandomAccessIterator is aLegacyRandomAccessIterator that additionally satisfies theLegacyOutputIterator requirements.
ConceptFor the definition ofstd::iterator_traits, the following exposition-only concept is defined.
where the exposition-only concept | (since C++20) |
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 ofa[n] was required to be convertible toconst value_type& | the return type is required to be convertible to reference |
| LWG 448 | C++98 | the return type ofa[n] was required to be convertible to value_type | the return type is required to be convertible toconst value_type&[1] |
| LWG 1079 | C++98 | b- a was defined usinga< b, resulted in circular definition | removeda< b from the definition |
| LWG 2114 (P2167R3) | C++98 | convertibility tobool was too weak to reflect the expectation of implementations | requirements strengthened |
(C++20) | specifies that abidirectional_iterator is a random-access iterator, supporting advancement in constant time and subscripting(concept)[edit] |
| Iterator library | provides definitions for iterators, iterator traits, adaptors, and utility functions |