|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ALegacyForwardIterator is aLegacyIterator that can read data from the pointed-to element.
UnlikeLegacyInputIterator andLegacyOutputIterator, it can be used in multipass algorithms.
If aLegacyForwardIteratorit originates from aContainer, thenit's value type is the same as the container's, so dereferencing (*it) obtains the container's value type.
Contents |
| Type | Definition |
X | A forward iterator type |
T | Thevalue type ofX (i.e.std::iterator_traits<X>::value_type) |
Ref | std::iterator_traits<X>::reference |
| Value | Definition |
| i,j | Values of typeX orconst X |
| r | A value of typeX& |
X satisfiesLegacyForwardIterator if all following conditions are satisfied:
X satisfiesLegacyInputIterator.X satisfiesDefaultConstructible.X is amutable iterator,Ref is a reference toT.X is a constant iterator,Ref is a reference toconst T.X providemulti-pass guarantee.| Expression | Type | Effects |
|---|---|---|
| r++ | convertible toconst X& | Equivalent toX x= r; ++r; return x;. |
| *i++ | Ref |
Thedomain of== for forward iterators is that of iterators over the sameunderlying sequence.
However,value-initialized forward iterators can be compared, and must compare equal to other value-initialized iterators of the same type. In other words, value-initialized forward iterators behave as if they refer past the end of the same empty sequence. | (since C++14) |
Two dereferenceable iteratorsa andb of typeX offer themulti-pass guarantee if all following conditions are satisfied:
X is a pointer type.ConceptFor the definition ofstd::iterator_traits, the following exposition-only concept is defined.
where the exposition-only concept | (since C++20) |
Unlike thestd::forward_iterator concept, theLegacyForwardIterator requirements requires dereference to return a reference.
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 1212 (N3066) | C++98 | the type of*i++ did not match the type of *i-- required byLegacyBidirectionalIterator | changed the type to Ref |
| LWG 1311 (N3066) | C++98 | “a== b implies++a==++b” alone did not offer multipass guarantee[1] | also requires “a== b implies++a!= b”[2] |
| LWG 3798 | C++20 | __LegacyForwardIterator requiredstd::iter_reference_t<It> to be an lvalue reference type | also allows rvalue reference types |
(C++20) | specifies that aninput_iterator is a forward iterator, supporting equality comparison and multi-pass(concept)[edit] |
| Iterator library | provides definitions for iterators, iterator traits, adaptors, and utility functions |