Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Iterator Traits

Iterator Traits

Author: David Abrahams
Contact: dave@boost-consulting.com
Organization: Boost Consulting
Date: $Date$
Copyright: Copyright David Abrahams 2004.
abstract:Header provides the ability to access an iterator's associated types using MPL-compatible metafunctions.

Overview

std::iterator_traits provides access to five associated types of any iterator: its value_type, reference, pointer, iterator_category, and difference_type. Unfortunately, such a "multi-valued" traits template can be difficult to use in a metaprogramming context. provides access to these types using a standard metafunctions.

Summary

Header :

template 
struct iterator_value
{
    typedef typename
      std::iterator_traits::value_type
    type;
};

template 
struct iterator_reference
{
    typedef typename
      std::iterator_traits::reference
    type;
};


template 
struct iterator_pointer
{
    typedef typename
      std::iterator_traits::pointer
    type;
};

template 
struct iterator_difference
{
    typedef typename
      detail::iterator_traits::difference_type
    type;
};

template 
struct iterator_category
{
    typedef typename
      detail::iterator_traits::iterator_category
    type;
};