filtered_iterator Class

class filtered_iterator

The filtered_iterator templated class is an iterator that skips elements that don't match your selection criteria. The template parameter to the filtered_iterator is the iterator to filter. The filtered_iterator derives from the iterator type passed in, and overrides the const_iterator::next and const_iterator::prev members to skip non-matching elements. Note, you can even have multiple levels of filtering by wrapping a filtered_iterator by another filtered_iterator.

To use the filtered_iterator, you must specify a selection criteria. There are two methods you can choose from. First, you can override the virtual select function, , and test the current element when called upon. If the element matches, the select function should return true. Otherwise, return false and the element will be skipped during iteration.

The second method is two declare a filter object and pass it into the constructor. To declare a filter object, derive a a class from the nested type . filter_type is a base class for a functor that implements operator(), and receives the current element as a parameter. The operator is expected to return true if the element is selected, or false if it should be skipped. To use the filtered_iterator, define a filter object and pass it into the filtered_iterator constructor.

Note, a filtered_iterator can also serve to implement a find feature. This method is preferable over a function because multiple finds are more easily dealt with.

Defined in: PolyIter.h

Class Template Arguments

_It

The type of iterator to wrap and filter.

Member functions include: filtered_iterator