21 #ifndef LUNCHBOX_INDEXITERATOR_H
22 #define LUNCHBOX_INDEXITERATOR_H
40 :
public std::iterator< std::random_access_iterator_tag, T >
44 : container_( container ), i_(i) {}
46 : container_( from.container_ ), i_( from.i_ ) {}
47 template<
class U,
class V,
class W >
49 : container_( from.container_ ), i_( from.i_ ) {}
53 container_ = rhs.container_;
55 return *
static_cast< S*
>( this );
58 template<
class U,
class W >
61 container_ = rhs.container_;
63 return *
static_cast< S*
>( this );
66 S& operator ++() { ++i_;
return *
static_cast< S*
>( this ); }
67 S& operator --() { --i_;
return *
static_cast< S*
>( this ); }
68 S operator ++ (
int) {
return S( container_, i_++ ); }
69 S operator -- (
int) {
return S( container_, i_-- ); }
71 S operator + (
const size_t& n )
const
72 {
return S( container_, i_+n ); }
73 S& operator += (
const size_t& n )
74 { i_ += n;
return *
static_cast< S*
>( this ); }
76 S operator - (
const size_t& n )
const
77 {
return S( container_, i_-n ); }
78 S& operator -= (
const size_t& n )
79 { i_ -= n;
return *
static_cast< S*
>( this ); }
81 ssize_t operator- (
const S& n )
const {
return i_ - n.i_; }
83 bool operator == (
const S& rhs )
const
84 {
return container_ == rhs.container_ && i_ == rhs.i_; }
85 bool operator != (
const S& rhs )
const
86 {
return container_ != rhs.container_ || i_ != rhs.i_; }
87 bool operator < (
const S& rhs )
const
88 {
return container_ <= rhs.container_ && i_ < rhs.i_; }
89 bool operator > (
const S& rhs )
const
90 {
return container_ >= rhs.container_ && i_ > rhs.i_; }
91 bool operator <= (
const S& rhs )
const
92 {
return container_ <= rhs.container_ && i_ <= rhs.i_; }
93 bool operator >= (
const S& rhs )
const
94 {
return container_ >= rhs.container_ && i_ >= rhs.i_; }
96 size_t getPosition()
const {
return i_; }
111 #endif // LUNCHBOX_INDEXITERATOR_H