|
|
Nicolas Alvarez wrote:
> Lambdas are just syntactic sugar to defining an anonymous function, where
> the code will end up stored somewhere else. Very similar to string literals
> really.
Uh, no, not really. They're only anonymous functions if you don't have any
free variables, at which point why bother?
>> If C++ added lambdas and they actually had things like pointers to stack
>> frames and so on, I'd probably not be bothered.
>
> std::for_each(someList.begin(), someList.end(), [&](int x) {
> total += x
> });
>
> "The specific internal implementation can vary, but the expectation is that
> the lambda function will store the actual stack pointer of the function it
> is created in, rather than individual references to stack variables."
So it's not really a closure, but a downward funarg. That's exactly the sort
of thing I was talking about. You can't return a lambda, I take it?
What's the type of
[&](int x) { total += x; }
What kind of variable can I assign that to?
> What makes you think C++0x won't modify the compiler?!
Well, that's good. The syntax, of course, is going to be baroque because
they're still trying to pretend they're upward compatible with C. :-)
--
Darren New, San Diego CA, USA (PST)
My fortune cookie said, "You will soon be
unable to read this, even at arm's length."
Post a reply to this message
|
|