Share via


iterator_traits

iterator_traits

template<class It>
    struct iterator_traits {
    typedef It::iterator_category iterator_category;
    typedef It::value_type value_type;
    typedef It::distance_type distance_type;
    };

The template class determines several critical types associated with the iterator type It. It defines the member types iterator_category (a synonym for It::iterator_category), value_type (a synonym for It::value_type), and distance_type (a synonym for It::distance_type).

In this implementation, if a translator does not support partial specialization of templates, you should use the template functions:

template<class C, class T, class Dist>
    C _Iter_cat(const iterator<C, T, Dist>&);
template<class T>
    random_access_iterator_tag _Iter_cat(const T *);

template<class C, class T, class Dist>
    T *_Val_type(const iterator<C, T, Dist>&);
template<class T>
    T *_Val_type(const T *);

template<class C, class T, class Dist>
    Dist *_Dist_type(const iterator<C, T, Dist>&);
template<class T>
    ptrdiff_t *_Dist_type(const T *);

which determine the same types somewhat less directly. You use these functions as arguments on a function call. Their sole purpose is to supply a useful template class parameter to the called function.