Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

Generic::index_iterator< C, TransformFnType > Class Template Reference

#include <index_iterator.h>

Collaboration diagram for Generic::index_iterator< C, TransformFnType >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<class C, class TransformFnType = Scale::Identity<typename C::value_type>>
class Generic::index_iterator< C, TransformFnType >

Simple iterator adapter class providing element indexes instead of elements.

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 * ()


The documentation for this class was generated from the following file:
Generated on Mon Jan 20 02:37:34 2003 for RF-LISSOM by doxygen1.3-rc2