|
|
Darren New wrote:
> Or do you think C++ is going to hoist those local variables into a
> separate object (like every other language implementing actual lambdas)?
> And if so, when does C++ deallocate that separate object, given there's
> no garbage collection?
For example, if you go to
http://download.microsoft.com/download/3/8/8/388e7205-bc10-4226-b2a8-75351c669b09/csharp%20language%20specification.doc
and look at section 7.14.4, you can see what C# supports in *its* lambdas.
Or http://msdn.microsoft.com/en-us/library/bb397687.aspx and go down to
"variable scope in lambdas" if you don't want to download the actual spec.
And when you nest lambdas in several scopes then reference variables from
those scopes, you get an even more complex set of declarations generated, in
order that (for example) the variable outside the loop your lambdas
reference are shared, while the variable inside the loop your lambdas
reference isn't shared.
I looked around to see if I could find the code that C# generates when you
give it a lambda with free variable references to multiple scopes (which,
yes, is just syntactic sugar), but I couldn't find it after 10 minutes or
so. If you really care, rather than just being interested in defending C++,
I'll take the time to hunt it down. But it's not something you can put in
C++ in the same way.
--
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
|
|