Re:Lambda-style anonymous functions for C++ in less than 500...
by Jach on Tuesday April 13, 2010 @11:48AM
(#1262343)
This is so much nicer than Boost's stuff. Quite the exploit but still awesome, it'll probably go into my next side-project.
[ Parent
| on HN ]
Re:Lambda-style anonymous functions for C++ in less than 500...
by sorbits on Tuesday April 13, 2010 @12:29PM
(#1262487)
Though it doesn’t work with the standard algorithms.
For example you can’t do stuff like:
std::transform(first, last, lambda<int> (x) --> 2*x);
Re:Lambda-style anonymous functions for C++ in less than 500...
by Jach on Tuesday April 13, 2010 @12:49PM
(#1262552)
What are you talking about? You're missing an arg in your transform() call.
int nums[] = {1, 2, 3};
printf("nums: %i %i %i\n", nums[0], nums[1], nums[2]);
std::transform(nums, nums+3, nums, (lambda<int> (x) --> 2*x));
printf("new nums: %i %i %i\n", nums[0], nums[1], nums[2]);
Edit: And of course, there's the implemented map he gives in the example: int* incs = (lambda<int> (x) --> x + 1).map(3,nums);
The class needs a little bit of work obviously (like more operators overloaded), but it's pretty nice.