on Sun Jul 22 2007, Scott Meyers
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.
Yes. Note "allowed," not "required." Incidentally, that allowed variation is why "input iterator" can't be an implicitly deduced concept. If vector<T>::insert were to mistakenly deduce an input iterator (single-pass) to be a (multipass) forward iterator, the library could crash or worse.
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.
True.
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.
I don't know how to judge whether anyone should be expected to know that. It's just a standard property of input iterators, like that they don't support operator+, but maybe it falls below some threshold of reasonable knowledge.
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.
Yes, it would be nice. IIUC not much effort is going into lambda stuff because it's supposed to be replaced by phoenix 2... but if you want to report a bug, please enter a ticket into the Boost trac at http://svn.boost.org; at least it will stand a chance of being addressed.
For the record, this compiles:
find_if(b2, e2, const_parameters(_1 == 'x'));
Thanks for the explanation.
Glad it helped. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com