IntIterator< T > Class Template Reference

A random access iterator over an integer type. More...

#include <IntIterator.h>

List of all members.

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.
IntIteratoroperator= (const IntIterator &other)
 Assignment operator.
 ~IntIterator ()
 Destructor.
Forward iterator requirements

reference operator* () const
 Dereference.
pointer operator-> () const
 Pointer dereference.
IntIteratoroperator++ ()
 Pre-increment.
IntIterator operator++ (int)
 Post-increment.
Bidirectional iterator requirements

IntIteratoroperator-- ()
 Pre-decrement.
IntIterator operator-- (int)
 Post-decrement.
Random access iterator requirements

value_type operator[] (const difference_type n)
 Iterator indexing.
IntIteratoroperator+= (const difference_type n)
 Positive offseting.
IntIterator operator+ (const difference_type n) const
 Positive offseting.
IntIteratoroperator-= (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.

Detailed Description

template<typename T = int>
class IntIterator< T >

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)); 

Member Function Documentation

template<typename T = int>
IntIterator IntIterator< T >::operator+ ( const difference_type  n  )  const [inline]

Positive offseting.

Note:
This is not efficient. If possible, use += instead.
template<typename T = int>
IntIterator IntIterator< T >::operator++ ( int   )  [inline]

Post-increment.

Note:
This is not efficient. If possible, use the pre-increment operator instead.
template<typename T = int>
IntIterator IntIterator< T >::operator- ( const difference_type  n  )  const [inline]

Negative offseting.

Note:
This is not efficient. If possible, use -= instead.
template<typename T = int>
IntIterator IntIterator< T >::operator-- ( int   )  [inline]

Post-decrement.

Note:
This is not efficient. If possible, use the pre-decrement operator instead.

Friends And Related Function Documentation

template<typename T >
IntIterator< T > constructIntIterator ( const T  x  )  [related]

Convenience function for instantiating an IntIterator.

template<typename T >
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.

template<typename T >
IntIterator< T > operator+ ( typename IntIterator< T >::difference_type  n,
const IntIterator< T > &  i 
) [related]

Iterator advance.

template<typename T >
IntIterator< T >::difference_type operator- ( const IntIterator< T > &  x,
const IntIterator< T > &  y 
) [related]

The difference of two iterators.

References IntIterator< T >::base().

template<typename T >
bool operator< ( const IntIterator< T > &  x,
const IntIterator< T > &  y 
) [related]

Return true if the index of x precedes that of y.

template<typename T >
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.

template<typename T >
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().

template<typename T >
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().


The documentation for this class was generated from the following file:
Generated on Thu Jun 30 02:14:51 2016 for Algorithms and Data Structures Package by  doxygen 1.6.3