Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2007-07-22 13:00:14


on Sun Jul 22 2007, Scott Meyers <usenet-AT-aristeia.com> wrote:

> The following code using Lambda with vector iterators compiles without complaint:
>
> vector<char> v;
> find_if(v.begin(), v.end(), _1 == 'x');
>
> Ditto for this code, which uses istream_iterators:
>
> istream_iterator<char> b1(cin);
> istream_iterator<char> e1;
> find_if(b1, e1, _1 == 'x');
>
> But the same code with istreambuf_iterators gets rejected:
>
> istreambuf_iterator<char> b2(cin);
> istreambuf_iterator<char> e2;
> find_if(b2, e2, _1 == 'x');
>
> Error messages from VC8 and gcc 4.1.1 are below. Am I doing something wrong, is
> there a bug in Lambda regarding istreambuf_iterators, or is this a restriction
> that I didn't see documented somewhere?

The issue is that istreambuf_iterator is an input iterator, not a
forward iterator, and thus is allowed to return from operator* by
value instead of reference (which it does).

http://tinyurl.com/37v98x#lambda.actual_arguments_to_lambda_functors
explains the problem and contains a link to a section about
workarounds.

HTH,

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
The Astoria Seminar ==> http://www.astoriaseminar.com

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