Namespaces
Variants
Views
Actions

Iterator library

From cppreference.com
< cpp
Revision as of 15:37, 20 August 2011 by Nate (Talk | contribs)

Template:cpp/iterator/sidebar

Iterators are a generalization of pointers that allow C++ programs to access different containers in a uniform manner. Any algorithm that accepts iterators should accept regular pointers also.

Contents

Iterator Types

Five iterator categories are defined, according to operations defined on them:

  • Input iterator
allows reading from the iterator object
allows iterating forward without multi-pass guarantee, i. e. reading the same element twice is not guaranteed to produce the same results
  • Output iterator
allows writing to the iterator object
allows iterating forward without multi-pass guarantee
  • Forward iterator
allows reading from the iterator object
allows iterating forward with multi-pass guarantee, i. e. reading the same element twice is guaranteed to produce the same results
  • Bidirectional iterator
allows reading from the iterator object
allows iterating forward and backward with multi-pass guarantee
  • Random access iterator
allows reading from the iterator object
allows iterating forward and backward randomly with multi-pass guarantee

Forward iterators satisfy the requirements of input iterators

Iterator Operations

Defined in header <iterator>
Advance an iterator by some distance
(function)
Returns the distance between two iterators
(function)
Increment an iterator
(function)
Decrement an iterator
(function)

Predefined Iterators

reverse_iterator, insert_iterator, move_iterator

Stream Iterators

istream_iterator, ostream_iterator, istreambuf_iterator

Range Access

Defined in header <iterator>
Returns an iterator to the beginning of a container
(function)
Returns an iterator to the end of a container
(function)