David Abrahams wrote:
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).
Of course, one has to know this. Note that the code works with istream_iterators, and they are also input iterators.
http://tinyurl.com/37v98x#lambda.actual_arguments_to_lambda_functors explains the problem and contains a link to a section about workarounds.
Technically, yes, it explains the problem, but it makes no mention of the implications for users of standard library iterator types. I, for one, did not know that operator* for istreambuf_iterator may return an rvalue, and I question whether I should be expected to know this. It would be nice if http://www.boost.org/doc/html/lambda/using_library.html#lambda.actual_argume... mentioned the conditions under which using Lambda with standard iterator types might not compile and called out istreambuf_iterator by name. At least then my Googling for information would have been likely to help. For the record, this compiles: find_if(b2, e2, const_parameters(_1 == 'x')); Thanks for the explanation. Scott