|
|
|
TheLegacyIterator requirements describe types that can be used to identify and traverse the elements of a container.
LegacyIterator is the base set of requirements used by other iterator types:LegacyInputIterator,LegacyOutputIterator,LegacyForwardIterator,LegacyBidirectionalIterator, andLegacyRandomAccessIterator. Iterators can be thought of as an abstraction of pointers.
All the categories of iterators require only those functions that are realizable for a given category in constant time (amortized). Therefore, requirement tablesand concept definitions(since C++20) for the iterators do not specify complexity.
Contents |
The typeIt
satisfiesLegacyIterator if
It
satisfiesCopyConstructible, andIt
satisfiesCopyAssignable, andIt
satisfiesDestructible, andIt
satisfiesSwappable, andvalue_type
,(until C++20)difference_type
,reference
,pointer
, anditerator_category
, andIt
, the following expressions must be valid and have their specified effects:Expression | Return Type | Precondition |
---|---|---|
*r | unspecified | r isdereferenceable |
++r | It& | r isincrementable (the behavior of the expression++r is defined) |
ConceptFor the definition ofstd::iterator_traits, the following exposition-only concept is defined.
where the exposition-only concept__Referenceable<T> is satisfied if and only ifT& is a valid type (in particular, | (since C++20) |
Note on terminology: The following table shows the names used on this site and corresponding C++ Standard names (with the same meaning).The "Legacy" (and “Cpp17”) prefix emphasizes compatibility with pre-C++20 standards and is used to distinguish these requirements from the newiterator concepts introduced with 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 2437 | C++98 | *r is required to bereference | not required for output iterators |
LWG 3420 | C++20 | the exposition-only concept checkscopyable first | copyable is checked only if the requires-expression yields true |
(C++20) | specifies that objects of a type can be incremented and dereferenced (concept)[edit] |
Iterator library | provides definitions for iterators, iterator traits, adaptors, and utility functions |