iterator and iterator_traits class in C++

iterator class: iterator class is declared as:

template <class Category, class D, class Diff = ptrdiff_d,

class Pointer = D *, class Ref = D &>

struct iterator {

typedef D val_type;

typedef Diff diff_type;

typedef Pointer pointer;

typedef Ref ref;

typedef Category it_category;


where, diff_type is used to hold difference between two addresses,

val_type is type of value

it_category is for type of iterator.

iterator_traits class: iterator_traits class is declared as:

template<class Iterator> struct iterator_traits {

typedef Iterator::difference_type diff_type;

typedef Iterator::value_type val_type;

typedef Iterator::pointer pointer;

typedef Iterator::reference reference;

typedef Iterator::iterator_category it_category;


Leave a Reply