# C++ named requirements: LegacyIterator

From cppreference.com
< cpp‎ | named req

The LegacyIterator 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, and LegacyRandomAccessIterator. Iterators can be thought of as an abstraction of pointers.

### Requirements

The type `It` satisfies LegacyIterator if

- The type `It` satisfies CopyConstructible, and
- The type `It` satisfies CopyAssignable, and
- The type `It` satisfies Destructible, and
- lvalues of type `It` satisfy Swappable, and
- std::iterator_traits<It> has member typedefs `value_type`, `difference_type`, `reference`, `pointer`, and `iterator_category` , and

Given

- `r`, an lvalue of type `It`.

The following expressions must be valid and have their specified effects:

Expression | Return Type | Precondition
--- | --- | ---
*r | unspecified | `r` is dereferenceable (see below)
++r | It& | `r` is incrementable (the behavior of the expression ++r is defined)

### Dereferenceable iterators

Iterators for which the behavior of the expression *i is defined are called dereferenceable.

Iterators are not dereferenceable if

- they are past-the-end iterators (including pointers past the end of an array) or before-begin iterators. Such iterators may be dereferenceable in a particular implementation, but the library never assumes that they are.
- they are singular iterators, that is, iterators that are not associated with any sequence. A null pointer, as well as a default-constructed pointer (holding an indeterminate value) is singular
- they were invalidated by one of the iterator-invalidating operations on the sequence to which they refer.

### Concept

For the definition of std::iterator_traits, the following exposition-only concept is defined.

template<class I> concept __LegacyIterator = std::Copyable<I> && requires(I i) { { *i } -> __Referenceable; { ++i } -> std::Same<I&>; { *i++ } -> __Referenceable; }; |  |

where the exposition-only concept `__Referenceable<T>` is satisfied if and only if `T&` is a valid type (in particular, `T` must not be void).

(since C++20)

### See also

Iterator | specifies that objects of a type can be incremented and dereferenced (concept)

- Iterator library

Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/named_req/Iterator&oldid=109806"