Boost logo

Boost :

From: David A. Greene (greened_at_[hidden])
Date: 2002-11-05 15:02:22


Hi,

I've been playing with iterator_adaptors lately -- great work
by all involved. I do have a question about the mechanics
of the library, though.

In the iterator_adaptor class we have this member (simplified
by removing Metrowerks special cases):

    self& operator--() {
         policies().decrement<self>(*this);
         return *this;
     }

We then have the filter_iterator policies that look like this:

template <class Predicate, class Iterator>
class filter_iterator_policies
{
public:
[...]
     template <class IteratorAdaptor>
     void increment(IteratorAdaptor& x) {
         ++x.base();
         satisfy_predicate(x.base());
     }

     template <class IteratorAdaptor>
     typename IteratorAdaptor::reference
     dereference(const IteratorAdaptor& x) const
         { return *x.base(); }

     template <class IteratorAdaptor1, class IteratorAdaptor2>
     bool equal(const IteratorAdaptor1& x, const IteratorAdaptor2& y)
     const
         { return x.base() == y.base(); }

  private:
     void satisfy_predicate(Iterator& iter);
     Predicate m_predicate;
     Iterator m_end;
};

Nowhere is "decrement" declared or defined in the filter_iterator
policies yet it can still be used with iterator_adaptor. How
does this work? Shouldn't the compiler complain that
iterator_adaptor::operator--() can't find
filter_iterator_policies::decrement? I could understand if
operator-- were a template member but it's not. I'm obviously
missing something. What is it?

                             -Dave

-- 
"Some little people have music in them, but Fats, he was all music,
  and you know how big he was."  --  James P. Johnson

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