00001
00007 #ifndef __INDEX_ITERATOR_H__
00008 #define __INDEX_ITERATOR_H__
00009
00010
00011 #include <iterator>
00012 #include <functional>
00013 #include "../src/scale.h"
00014
00015 namespace Generic {
00016
00017
00043 template <class C, class TransformFnType=Scale::Identity<typename C::value_type> >
00044 class index_iterator {
00045 typedef index_iterator self;
00046 typedef C Container;
00047
00048 typedef typename Container::iterator iterator;
00049 typedef typename Container::const_iterator const_iterator;
00050 typedef typename Container::size_type size_type;
00051
00052 public:
00055 typedef std::input_iterator_tag iterator_category;
00056 typedef typename Container::value_type value_type;
00057 typedef typename Container::difference_type difference_type;
00058 typedef typename Container::value_type* pointer;
00059 typedef typename Container::value_type reference;
00061
00063 index_iterator(const const_iterator& i_, TransformFnType fn_=TransformFnType())
00064 : i(i_), c(0), fn(fn_) {}
00065
00068 bool operator==(const self& o) { return (o.i == i); }
00069 bool operator!=(const self& o) { return (o.i != i); }
00070 self& operator++ () { ++i; ++c; return *this; }
00071 self& operator++ (int) { i++; c++; return *this; }
00072
00073 reference operator* () { return fn(c); }
00075
00077 const value_type& value() const { return *i; }
00078
00079 private:
00080 const_iterator i;
00081 size_type c;
00082
00083 TransformFnType fn;
00084 };
00085
00086
00087
00088 }
00089 #endif