Namespaces
Variants
Views
Actions

Iterator library

From cppreference.com
< cpp
Revision as of 14:46, 6 June 2011 by P12 (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.

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