20 #ifndef LUNCHBOX_INDEXITERATOR_H
21 #define LUNCHBOX_INDEXITERATOR_H
39 :
public std::iterator< std::random_access_iterator_tag, T >
44 : container_( container ), i_(i) {}
48 : container_( from.container_ ), i_( from.i_ ) {}
51 template<
class U,
class V,
class W >
53 : container_( from.container_ ), i_( from.i_ ) {}
59 container_ = rhs.container_;
61 return *
static_cast< S*
>( this );
65 template<
class U,
class W >
68 container_ = rhs.container_;
70 return *
static_cast< S*
>( this );
87 {
return S( container_, i_+n ); }
91 { i_ += n;
return *
static_cast< S*
>( this ); }
95 {
return S( container_, i_-n ); }
99 { i_ -= n;
return *
static_cast< S*
>( this ); }
102 ssize_t
operator- (
const S& n )
const {
return i_ - n.i_; }
106 {
return container_ == rhs.container_ && i_ == rhs.i_; }
110 {
return container_ != rhs.container_ || i_ != rhs.i_; }
114 {
return container_ <= rhs.container_ && i_ < rhs.i_; }
118 {
return container_ >= rhs.container_ && i_ > rhs.i_; }
125 {
return container_ <= rhs.container_ && i_ <= rhs.i_; }
132 {
return container_ >= rhs.container_ && i_ >= rhs.i_; }
150 #endif // LUNCHBOX_INDEXITERATOR_H
IndexIterator(C *container, const size_t i)
Construct an iterator for a given container and position.
Counter-based, as opposed to pointer-based, iterator for any container.
bool operator==(const S &rhs) const
S operator-(const size_t &n) const
Decrement the iterator position by a given amount.
bool operator>(const S &rhs) const
bool operator>=(const S &rhs) const
size_t getPosition() const
S & operator=(const IndexIterator &rhs)
Assign the container and position from another iterator.
bool operator<=(const S &rhs) const
IndexIterator(const S &from)
Copy-construct an iterator.
S & operator++()
Increment the iterator position.
S & operator+=(const size_t &n)
Increment the iterator position by a given amount.
Abstraction layer and common utilities for multi-threaded programming.
bool operator<(const S &rhs) const
S & operator-=(const size_t &n)
Decrement the iterator position by a given amount.
S & operator--()
Decrement the iterator position.
bool operator!=(const S &rhs) const
S operator+(const size_t &n) const
Increment the iterator position by a given amount.
IndexIterator(const IndexIterator< U, V, W > &from)
Copy-construct an iterator.