Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-02-23 10:05:00


Nico Galoppo <nico_at_[hidden]> 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

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net