lambda functions
Posted Dec 8, 2005 10:03 UTC (Thu) by
pkolloch (subscriber, #21709)
Parent article:
The Boost C++ Libraries
One of the very impressive features are lambda functions (IMHO):
for_each(a.begin(), a.end(), std::cout << _1 << ' ');
"std::cout << _1 << ' '" defines lambda function object taking one parameter.
Unfortunately, one cannot totally freely define those. Correct me, if I am wrong, but the following should not be possible:
for_each(a.begin(), a.end(), std::cout << "blupps: " << _1 << ' ');
The "<<" is evaluated from left to right. That means that std:cout << "blupps: " is evaluated before the special magic _1 can interfere and "blupps: " is printed immediately. (there is some special function to make this possible, I do not remember)
Functional conditional statements like "if_then" etc. are also provided for usage inside of lambda functions.
(
Log in to post comments)