First page Back Continue Last page Overview Graphics
Iteration in C++
Iterators in C++ are pointer-like objects.
“Get next” idiom via pre-/post-increment of an iterator. The value is accessed via the iterator.
“Foreach” idiom via a for loop or for_each() on a function or a functor. The value is passed to the function/functor.
Notes:
A functor is a function-like object. More exactly it's an instance of a class than overrides operator(), the function call operator.
Functors are similar to closures in Perl. They allow you to construct functions that have some internal state. E.g.: a functor called less than, where the constructor takes a parameter than defines what to compare against.