Boost logo

Boost :

From: Gary Powell (Gary.Powell_at_[hidden])
Date: 2001-01-23 13:12:35


> Looking forward to supporting more of the adaptors from the VTL,
> how about we add filter iterator to the iterator adaptors?
>
Sounds like a good idea to me!
(Martin and I would like to convert VTL to use this design.
Martin is busy with his Ph.d. and I am busy with LL, but soon.)

> It looks like we need to add an initialize() function to the
> policies interface in order to do this.
>
> template <class Predicate, class Iterator>
> class filter_iterator_policies : public default_iterator_policies {
> public:
> filter_iterator_policies() { }
>
> filter_iterator_policies(const Predicate& p, const Iterator& end)
> : m_predicate(p), m_end(end) { }
>
> void initialize(Iterator& x) {
> while (!m_predicate(*x) && x != m_end)
> ++x;
> }
> void increment(Iterator& x) {
> ++x;
> while (!m_predicate(*x) && x != m_end) // if x == m_end *x is
> undefined.
> ++x;
> }
> private:
> Predicate m_predicate;
> Iterator m_end;
> };
>
// Better to write an "advance"

void advance(itertype iter)
{
   while (m.end != iter && // test that it is valid first.
          !pred(*iter) ))
   ++iter;
}

  Yours,
 -gary-

gary.powell_at_[hidden]


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