A random access iterator over an integer type. More...
#include <IntIterator.h>
Public Types | |
typedef Base::iterator_category | iterator_category |
The iterator category. | |
typedef Base::value_type | value_type |
The value type. | |
typedef Base::difference_type | difference_type |
Pointer difference type. | |
typedef Base::pointer | pointer |
Pointer to the value type. | |
typedef Base::reference | reference |
Reference to the value type. | |
Public Member Functions | |
Constructors etc. | |
IntIterator () | |
IntIterator (const value_type x) | |
Construct and initialize the value. | |
IntIterator (const IntIterator &x) | |
Copy constructor. | |
IntIterator & | operator= (const IntIterator &other) |
Assignment operator. | |
~IntIterator () | |
Destructor. | |
Forward iterator requirements | |
reference | operator* () const |
Dereference. | |
pointer | operator-> () const |
Pointer dereference. | |
IntIterator & | operator++ () |
Pre-increment. | |
IntIterator | operator++ (int) |
Post-increment. | |
Bidirectional iterator requirements | |
IntIterator & | operator-- () |
Pre-decrement. | |
IntIterator | operator-- (int) |
Post-decrement. | |
Random access iterator requirements | |
value_type | operator[] (const difference_type n) |
Iterator indexing. | |
IntIterator & | operator+= (const difference_type n) |
Positive offseting. | |
IntIterator | operator+ (const difference_type n) const |
Positive offseting. | |
IntIterator & | operator-= (const difference_type n) |
Negative offseting. | |
IntIterator | operator- (const difference_type n) const |
Negative offseting. | |
value_type | base () const |
Return the value. | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename T > | |
IntIterator< T > | constructIntIterator (const T x) |
Convenience function for instantiating an IntIterator. | |
template<typename T > | |
bool | operator== (const IntIterator< T > &x, const IntIterator< T > &y) |
Return true if the iterators have a handle to the same index. | |
template<typename T > | |
bool | operator!= (const IntIterator< T > &x, const IntIterator< T > &y) |
Return true if the iterators do not have a handle to the same index. | |
template<typename T > | |
bool | operator< (const IntIterator< T > &x, const IntIterator< T > &y) |
Return true if the index of x precedes that of y . | |
template<typename T > | |
bool | operator> (const IntIterator< T > &x, const IntIterator< T > &y) |
Return true if the index of x follows that of y . | |
template<typename T > | |
bool | operator<= (const IntIterator< T > &x, const IntIterator< T > &y) |
Return true if the index of x precedes or is equal to that of y . | |
template<typename T > | |
IntIterator< T >::difference_type | operator- (const IntIterator< T > &x, const IntIterator< T > &y) |
The difference of two iterators. | |
template<typename T > | |
IntIterator< T > | operator+ (typename IntIterator< T >::difference_type n, const IntIterator< T > &i) |
Iterator advance. |
A random access iterator over an integer type.
Suppose that you need to input a range of consecutive integers to a algorithm. Instead of having to build a container and fill it with these values, you can use an IntIterator. This iterator just stores an integer value. Dereferencing returns this value. Incrementing the iterator increments the value. Likewise, decrementing and offseting just operator an the stored integer value.
As an example, intsead of using a container:
std::vector<int> indices; for (int n = 0; n != 100; ++n) { indices.push_back(n); } foo(indices.begin(), indices.end());
one can use IntIterator:
IntIterator begin(0), end(100); foo(begin, end);
One can make the code more compact by using constructIntIterator() to construct the IntIterator's.
foo(constructIntIterator(0), constructIntIterator(100));
IntIterator IntIterator< T >::operator+ | ( | const difference_type | n | ) | const [inline] |
Positive offseting.
+=
instead. IntIterator IntIterator< T >::operator++ | ( | int | ) | [inline] |
Post-increment.
IntIterator IntIterator< T >::operator- | ( | const difference_type | n | ) | const [inline] |
Negative offseting.
-=
instead. IntIterator IntIterator< T >::operator-- | ( | int | ) | [inline] |
Post-decrement.
IntIterator< T > constructIntIterator | ( | const T | x | ) | [related] |
Convenience function for instantiating an IntIterator.
bool operator!= | ( | const IntIterator< T > & | x, | |
const IntIterator< T > & | y | |||
) | [related] |
Return true if the iterators do not have a handle to the same index.
IntIterator< T > operator+ | ( | typename IntIterator< T >::difference_type | n, | |
const IntIterator< T > & | i | |||
) | [related] |
Iterator advance.
IntIterator< T >::difference_type operator- | ( | const IntIterator< T > & | x, | |
const IntIterator< T > & | y | |||
) | [related] |
The difference of two iterators.
References IntIterator< T >::base().
bool operator< | ( | const IntIterator< T > & | x, | |
const IntIterator< T > & | y | |||
) | [related] |
Return true if the index of x
precedes that of y
.
bool operator<= | ( | const IntIterator< T > & | x, | |
const IntIterator< T > & | y | |||
) | [related] |
Return true if the index of x
precedes or is equal to that of y
.
bool operator== | ( | const IntIterator< T > & | x, | |
const IntIterator< T > & | y | |||
) | [related] |
Return true if the iterators have a handle to the same index.
References IntIterator< T >::base().
bool operator> | ( | const IntIterator< T > & | x, | |
const IntIterator< T > & | y | |||
) | [related] |
Return true if the index of x
follows that of y
.
References IntIterator< T >::base().