Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide


Library:  Iterators

Does not inherit

Local Index

No Entries


Returns basic information about an iterator.


#include <iterator>

namespace std { 
  template <class Iterator>
  struct iterator_traits;


The class template iterator_traits and its specializations allow algorithms to access information about a particular iterator in a uniform way. The template requires either an iterator with a basic interface consisting of the types value_type, difference_type, pointer, reference, and iterator_category, or it requires a specialization for the iterator. The library includes partial specializations to handle all pointer types.

iterator_traits are used within algorithms to create local variables of either the type pointed to by the iterator or of the iterator's distance type. The traits also improve the efficiency of algorithms by making use of knowledge about basic iterator categories provided by the iterator_category member. An algorithm can use this "tag" to select the most efficient implementation an iterator is capable of handling without sacrificing the ability to work with a wide range of iterator types. For instance, both the advance() and distance() primitives use iterator_category to maximize their efficiency by using the tag to select from one of several different auxiliary functions. The iterator_category must therefore be one of the iterator tags included by the library.


Tag Types

iterator_traits<>::iterator_category is typically used like this:

See the iterator section for a description of iterators and the capabilities associated with each type of iterator tag.

See Also

__value_type(), __distance_type(), __iterator_category(), distance(), advance(), iterator

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 24.3.1

Previous fileTop of DocumentContentsIndex pageNext file