Boost logo

Boost :

From: troy d. straszheim (troy_at_[hidden])
Date: 2004-12-01 09:51:29


I hit send and thought maybe that wasn't completely clear, sorry about
that. Here's a use-case:

  //
  // pure virtual base class
  //
  struct int_predicate
  {
    virtual ~int_predicate(){};
    virtual bool operator()(int x) = 0;

  protected:
    int_predicate(){};
  private:
    int_predicate(const int_predicate&);
    int_predicate& operator=(const int_predicate&);
  };
  
  struct is_positive_number : public int_predicate
  {
    virtual bool operator()(int x) { return x > 0; }
  };

  array<int, 10> a = { 0, -1, 2, -3, 4, -5, 6, -7, 8, -9 };

  is_positive_number pos;

  int_predicate &ispos_ref = pos;

  for (filter_iterator<int_predicate,array<int,10>::iterator> iter =
         make_filter_iterator<int_predicate>(ispos_ref, a.begin(), a.end());
       iter.base() != iter.end();
       iter++)
    {
      // whatever
    }

troy d. straszheim writes:
>
> Hi boost,
>
> The filter_iterator as implemented disallows creating iterators via
> reference-to-base, as it requires its Predicate objects to be
> copy-constructible. This is a problem for a class that is passed a
> ref to a predicate from elsewhere. It's a very easy fix, though, I'm
> wondering what the rationale originally was for the restriction. If
> it isn't significant, I'd propose the change below, as (at least from
> my narrow perspective) it is a big plus to be able to do this.
>
>
> 56c56
> < filter_iterator(Predicate& f, Iterator x, Iterator end = Iterator())
> ---
> > filter_iterator(Predicate f, Iterator x, Iterator end = Iterator())
> 82c82
> < const Predicate& predicate() const { return m_predicate; }
> ---
> > Predicate predicate() const { return m_predicate; }
> 106c106
> < Predicate& m_predicate;
> ---
> > Predicate m_predicate;
> 112c112
> < make_filter_iterator(Predicate& f, Iterator x, Iterator end = Iterator())
> ---
> > make_filter_iterator(Predicate f, Iterator x, Iterator end = Iterator())
>
>
> Thanks for your time,
>
> -t

-- 
troy d. straszheim                                         
............................................................................
landline:       (49) 30 9120 6877   [to direct dial from the us prepend 011] 
AIM:            thetroyeffect
IRC/efnet:      phoniq
skype.com:      straszheim
Why do so many CS majors confuse Halloween and Christmas?
Because Oct 31 is Dec 25.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk