iterator class template — Iterator base-class template
template<typename Category, typename T, typename Difference = ptrdiff_t, typename Pointer = T*, typename Reference = T&> struct iterator{ typedef T value_type; typedef Difference difference_type; typedef Pointer pointer; typedef Reference reference; typedef Category iterator_category; };
The iterator
class template
is a convenient base-class template to use when implementing your
own iterator.
The following are the template parameters, which are all type parameters:
Category
Must be one of the five iterator category tags: bidirectional_iterator_tag
, forward_iterator_tag
, input_iterator_tag
, output_iterator_tag
, or random_access_iterator_tag
.
T
The element type. It can be void
for an output iterator because
you cannot dereference an output iterator.
Difference
An integral type that represents the distance between
two iterators. It can be void
for an output iterator because
you cannot measure the distance between two output iterators.
This parameter is optional; the default is ptrdiff_t
, which is suitable for
typical pointer-like iterators.
Pointer
The pointer-to-element type. This parameter is optional;
the default is T*
, which is
correct for most iterators.
Reference
The reference-to-element type. This parameter is
optional; the default is T&
, which is correct for most
iterators.