C++ concepts: Iterator - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# C++ concepts: Iterator

From cppreference.com
< cpp‎ | concept

The `Iterator` concept describes types that can be used to identify and traverse the elements of a container.

`Iterator` is the base concept used by other iterator types: `InputIterator`, `OutputIterator`, `ForwardIterator`, `BidirectionalIterator`, and `RandomAccessIterator`. Iterators can be thought of as an abstraction of pointers.

### [edit] Requirements

The type `It` satisfies `Iterator` 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

Given

- `r`, an lvalue of type `It`,
- `reference`, the type denoted by std::iterator_traits<It>::reference

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 (see below)

### [edit] Dereferenceable iterators

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

`Iterator`s 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.

Iterators for which the behavior of the expression ++i is defined are called incrementable.

### [edit] See also

- Iterator library

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/concept/Iterator&oldid=78489"