tlp::StlFilterIterator< VALUE, ITERATOR, FILTER > Class Template Reference
[Iterator]
Iterator that enables to filter a Stl Iterator.
More...
#include <stlfilteriterator.h>
List of all members.
Public Member Functions
- StlFilterIterator (const ITERATOR &startIt, const ITERATOR &endIt, FILTER filter)
- VALUE next ()
- Moves the Iterator on the next element.
- bool hasNext ()
- Tells if the sequence is at its end.
Detailed Description
template<typename VALUE, typename ITERATOR, typename FILTER>
class tlp::StlFilterIterator< VALUE, ITERATOR, FILTER >
Iterator that enables to filter a Stl Iterator.
- Parameters:
-
| startIt | the beginning of the iterator that should be filtered (begin()) |
| endIt | the end of the iterator that should be filtered (begin()) |
| filter | the functor that enables to test wheter or not an element is filtered |
That example enable to iterate only of elements greater than 50;
class GreaterFilter {
GreaterFilter(double threshold):_t(threshold){
}
bool operator()(double a) {
return a < _t;
}
};
int main() {
vector<double> vec(100);
for (size_t j=0; j<100; ++j)
vec[j] = j;
GreaterFilter filter(50);
double x;
forEach(x, new StlFilterIterator<double, vector<double>::const_iterator>(vec.begin(), vec.end(), filter)) {
cout << x << endl;
}
Constructor & Destructor Documentation
template<typename VALUE , typename ITERATOR , typename FILTER >
Member Function Documentation
template<typename VALUE , typename ITERATOR , typename FILTER >
Tells if the sequence is at its end.
- Returns:
- bool Whether there are more elements to iterate on.
Implements tlp::Iterator< VALUE >.
template<typename VALUE , typename ITERATOR , typename FILTER >