filter_iterator usage

Hi, I have a class with some custom iterators, I would like to add another custom iterator that is a 'filtered' version of the custom iterator. Something like this: class A { public: typedef boost::filter_iterator<predicate_type, custom_iterator> filtered_iterator; filtered_iterator begin() { predicate_type predicate = boost::bind(...); return boost::make_filter_iterator(predicate, custom_begin(), custom_end()); } } Unfortunately, the following code doesn't compile: A a; A::filtered_iterator it = a.begin(); Reason: cannot convert from 'boost::filter_iterator<Predicate,Iterator>' to 'const boost::filter_iterator<Predicate,Iterator>' I can give more compiler output if needed. Thanks! --nico -- nico galoppo von borries @ address: 105 creel st., chapel hill comp. graphics phd. student @ north carolina, 27516 USA UNC, chapel hill @ phone: +1 (919) 962-1898 (office) @ +1 (919) 942-7609 (home) @ email: nico at cs dot unc dot edu @ homepage: http://www.cs.unc.edu/~nico --- debian linux :: vim powered

Nico Galoppo <nico@crossbar.net> writes:
Hi,
I have a class with some custom iterators, I would like to add another custom iterator that is a 'filtered' version of the custom iterator. Something like this:
class A { public: typedef boost::filter_iterator<predicate_type, custom_iterator> filtered_iterator;
filtered_iterator begin() { predicate_type predicate = boost::bind(...); return boost::make_filter_iterator(predicate, custom_begin(), custom_end()); } }
Unfortunately, the following code doesn't compile:
A a; A::filtered_iterator it = a.begin();
Reason: cannot convert from 'boost::filter_iterator<Predicate,Iterator>' to 'const boost::filter_iterator<Predicate,Iterator>'
I can give more compiler output if needed.
Most likely the important output is in the following lines in a pair of "with" clauses. In the two clauses, you should expect to see that either Predicate or Iterator don't match up. I suggest you not use make_filter_iterator when you already know the type of iterator you're creating anyway. Instead, just use constructor syntax: return filtered_iterator(predicate, custom_begin(), custom_end()); -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Nico Galoppo