#include <index_iterator.h>
Collaboration diagram for Generic::index_iterator< C, TransformFnType >:
Given an input_iterator, creates an input_iterator that when dereferenced returns the number of times it has been incremented so far, rather than the underlying value. (The underlying value may still be accessed through the value() operation.) This class is useful for treating a container as if it held indexes rather than data values, for use with standard algorithms. Example:
typedef std::vector<int> V; typedef index_iterator<V> iiv; V v; //... // List the elements of v, in order, followed by their indexes, in order: std::copy( v.begin(), v.end(), std::ostream_iterator<int>(std::cout," ")); std::cout << "
" std::copy(iiv(v.begin()),iiv(v.end()),std::ostream_iterator<int>(std::cout," ")); std::cout << "
"
If desired a function of the specified TransformFnType can be supplied; it will be applied to the index before returning it, e.g. to scale it to a desired range.
Definition at line 44 of file index_iterator.h.
Public Types | |
Types required for iterators | |
typedef std::input_iterator_tag | iterator_category |
typedef Container::value_type | value_type |
typedef Container::difference_type | difference_type |
typedef Container::value_type * | pointer |
typedef Container::value_type | reference |
Public Methods | |
index_iterator (const const_iterator &i_, TransformFnType fn_=TransformFnType()) | |
Constructor. | |
const value_type & | value () const |
Returns the value() of the underlying iterator. | |
Operations required for input_iterators | |
bool | operator== (const self &o) |
bool | operator!= (const self &o) |
self & | operator++ () |
self & | operator++ (int) |
reference | operator * () |