On Wed, Jan 5, 2011 at 5:13 PM, Dave Abrahams <dave@boostpro.com> wrote:
At Wed, 5 Jan 2011 16:05:56 +0000,
Robert Jones wrote:
>
> I might be asking for the impossible here, but given the lovely adaptor
> syntax, eg
>
> std::vector<int> vec;
> boost::copy( vec | boost::adaptors::reversed
>                  | boost::adaptors::uniqued,
>              std::ostream_iterator<int>(std::cout) );
>
>
> I notice it still uses the function call notation in the outermost
> operation( boost::copy() ),
> can it be written to eliminate function call syntax completely, say
> something like
>
> vec | boost::adaptors::reversed | boost::adaptors::uniqued |
> boost::adaptors::copy( std::ostream_iterator<int>(std::cout) );
>
> or even
>
> vec | boost::adaptors::reversed | boost::adaptors::uniqued |
> std::ostream_iterator<int>(std::cout);

It could be done, but it might not make much sense.  The boost
adaptors are essentially lazy sequence transformations, but the copy
operation you're asking for has a completely different nature: it's
eager.  If you still like that syntax, though, you could write a
suitable copy function of your own in about 40 lines that would do the
same job.

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?

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.

I'm not sure that it would be possible to implement it unambiguously tho'.

- Rob.