[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]
|
CountingIterator< T > Class Template Reference | ![]() |
Iterator that counts upwards or downwards with a given step size. More...
#include <vigra/counting_iterator.hxx>
Inherits iterator< std::random_access_iterator_tag, T, std::ptrdiff_t, T const *, T >.
Iterator that counts upwards or downwards with a given step size.
This iterator replicates the functionality of Python's well-known range-function. It is especially convenient in range-based for-loops. CountingIterator also works for floating-point counting.
Usage:
#include <vigra/counting_iterator.hxx>
Namespace: vigra
You will normally construct instances of this iterator with one of the range() factory functions. There are three versions of this function range(end), range(begin, end), and range(begin, end, step).
Alternatively, you can create a traditional random-access iterator pair. The end iterator can be conveniently constructed by the begin iterator's end() function:
range() and CountingIterator also work for floating-point arguments. As in the integer case, the upper bound is excluded from the range if it can be reached by an integer multiple of the step (within machine epsilon):
If you use an iterator pair, you can make clear which behavior you want by using either iter < end or iter <= end to terminate the loop:
Note that the termination condition is still iter <= end, even when the iterator counts downwards:
|
© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) |
html generated using doxygen and Python
|