|
Boost Users : |
Subject: Re: [Boost-users] [Range] Adaptors
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2011-01-06 10:17:01
On Thu, Jan 6, 2011 at 2:51 PM, Dave Abrahams <dave_at_[hidden]> wrote:
> At Thu, 6 Jan 2011 13:23:11 +0000,
> Robert Jones wrote:
> >
> > Yes.... I take your point about eager vs lazy, but on reflection is it
> not
> > the case that almost any 'pipeline' of transformations has to end with
> > 'eager' consumption?
>
> No, it is not. In some languages, everything is lazy, and the only
> thing that eventually forces evaluation is I/O. You can easily pass
> around, store, and compose lazy ranges to your heart's content.
>
> > If I had
> >
> > int f( int );
> >
> > boost::for_each( vec | boost::adaptors::reversed |
> boost::adaptors::uniqued,
> > f );
> >
> > and instead were able to write it as
> >
> > vec | boost::adaptors::reversed | boost::adaptors::uniqued | f;
> >
> > the final use of operator|() seems to pretty much imply eagerness in the
> > same way that the for_each() does.
>
> Only if you happen to know that f is a function and will be treated
> completely differently from the range adaptors.
>
>
Absolutely, now we're on the same page. There must be some identifiable
quality
of the last element of the pipeline that indicates that it is a consumer of
the
elements of the range. I'm unsure that any such reasonable test could be
devised, which is what makes such a facility hard to write.
Just musing on this.... if the 'thing' is a function-like object that
accepts arguments
of the type of elements of the range (or convertible), could it be
reasonably assumed
to consume the range?
- Rob.
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