Finally, the following for_each call outputs the sorted content of vp separated by line breaks:for_each(vp.begin(), vp.end(), cout << *_1 << "\n");
But wait, it gets much better.
Note that a normal (non-lambda) expression as subexpression of a lambda expression is evaluated immediately. This may cause surprises. For instance, if the previous example is rewritten asfor_each(vp.begin(), vp.end(), cout << "\n" << *_1);
the subexpression cout << "\n" is evaluated immediately and the effect is to output a single line break, followed by the elements of vp.
I'd love to see the compiler messages you get when you make a typo.
(An old post from Lambda the Ultimate has more information.)Posted by jjwiseman at May 26, 2004 11:10 AM