Hide the predicate type of a filter_iterator?

Hello everyone
Imagine a class "numbers" that contains some values and methods like
getEvenValues(), getOddValues(), getValuesLarger100() etc. Those methods
return an iterator range of filter_iterators. In the the code I posted
below, I'd have to define a different iterator_range of filter_iterator
types for all the different methods (numbers::EvenFilterRange,
numbers::OddFilterRange etc.). Is there some way to "hide" the type of
the predicate used in a filter_iterator, so that it would be possible to
have a generic "NumberRange" type for the return values of all methods?
Something like:
class numbers {
typedef NumberRange ????;
NumberRange getEvenValues() const;
NumberRange getOddValues() const;
NumberRange getValuesLarger100() const;
}
Thanks for your hints
James
/*********************************************/
#include <vector>
#include <iostream>
#include

AMDG Jean-Pierre Bergamin wrote:
Hello everyone
Imagine a class "numbers" that contains some values and methods like getEvenValues(), getOddValues(), getValuesLarger100() etc. Those methods return an iterator range of filter_iterators. In the the code I posted below, I'd have to define a different iterator_range of filter_iterator types for all the different methods (numbers::EvenFilterRange, numbers::OddFilterRange etc.). Is there some way to "hide" the type of the predicate used in a filter_iterator, so that it would be possible to have a generic "NumberRange" type for the return values of all methods? Something like:
class numbers { typedef NumberRange ????; NumberRange getEvenValues() const; NumberRange getOddValues() const; NumberRange getValuesLarger100() const; }
Try using boost::function

Hello again Steven Watanabe wrote:
AMDG
Jean-Pierre Bergamin wrote:
Hello everyone
Imagine a class "numbers" that contains some values and methods like getEvenValues(), getOddValues(), getValuesLarger100() etc. Those methods return an iterator range of filter_iterators. In the the code I posted below, I'd have to define a different iterator_range of filter_iterator types for all the different methods (numbers::EvenFilterRange, numbers::OddFilterRange etc.). Is there some way to "hide" the type of the predicate used in a filter_iterator, so that it would be possible to have a generic "NumberRange" type for the return values of all methods? Something like:
class numbers { typedef NumberRange ????; NumberRange getEvenValues() const; NumberRange getOddValues() const; NumberRange getValuesLarger100() const; }
Try using boost::function
for the predicate type.
Thank you Steven. Using boost::function as the predicate type does the
trick. For the sake of completeness, I post some code at the bottom.
I think this is a very useful method to provide filtered values to a
user, without copying any elements.
Regards
James
/*********************************************/
#include <vector>
#include <iostream>
#include

Jean-Pierre Bergamin schrieb:
Hello again
Steven Watanabe wrote:
Try using boost::function
for the predicate type. Thank you Steven. Using boost::function as the predicate type does the trick. For the sake of completeness, I post some code at the bottom. I think this is a very useful method to provide filtered values to a user, without copying any elements.
Copying is of course only avoided if the Predicate function is defined
as boost::function
participants (2)
-
Jean-Pierre Bergamin
-
Steven Watanabe