|
Boost : |
From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 1999-08-18 08:22:33
Greg Colvin wrote:
>
> > Greg Colvin wrote:
> > >
> > > From: Valentin Bonnard <Bonnard.V_at_[hidden]>
> > > > A priori, writing a skiping iterator seems trivial:
> > > >
> > > > template <typename It, typename Predicate>
> > > > class SkippingIterator {
> > > > mutable It pos;
> > > > Predicate pred;
> > > >
> > > > void skip () const
> > > > { while (pred (*pos)) ++pos; }
> > > >
> > > > public:
> > > > value_type& operator* () const
> > > > { skip (); return *pos; }
> > > >
> > > > void operator++ ()
> > > > { skip(); ++pos; }
> > > > };
> > > >
> > > > Except that the semantic near the end is ugly (the precondition
> > > > is that there are non skipped elements before the end).
> > >
> > > I think the precondition is just that pred(*last) is false.
> >
> > Saying pred(*x) is false is saying that x is non skipped.
> >
> > We are saying the same thing.
>
> You are right. The difference is just whether the end iterator
> is passed to the SkippingIterator constructor or the Predicate
> constructor.
No. The Predicate deals with values, not iterators. The
SkippingIterator must have a way to know when it must stop.
pred(last_object) must be false. Passing the value of the
last object to the predicate is possible but it would
mean that every object with the same value as the last
object isn't skipped. In any case the semantic is
between low level, ugly, and unusable.
> > This precondition is ugly (why would the elements
> > at some position be skippable and not the others ?)
>
> So you don't skip off the end of the sequence. There is no
> element to skip at the end.
???
-- Valentin Bonnard
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk