C++0x now with lambda and closure
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Fri Apr 11 07:20:30 PDT 2008
Sean Kelly wrote:
> == Quote from Bruno Medeiros (brunodomedeiros+spam at com.gmail)'s article
>> guslay wrote:
>>> For those keeping track...
>>>
>>> http://herbsutter.spaces.live.com/
>>>
>>> Crazy syntax, at least it looks better than boost.
>>>
>> What happens to the outer variables? Is a copy of them created for each
>> evaluated closure object? Or does there exist only a single instance of
>> each, as in D?
>> And how is the closure object destroyed, since there is no GC? (does one
>> have to assign it to a variable, to later delete it?)
>> I tried to read the proposal to find an answer, but I couldn't quickly
>> grasp it.
>
> From memory, it looked like variables could either be copied or manipulated
> by reference, and that the closure object was basically just an opaque struct
> much like a plain old functor.
>
>
> Sean
Yes, that seems to make sense all around.
I was originally surprised by this announcement because it was not
possible for C++ to implement "full" closures without having a GC. So it
was either closures with outer variables that became invalid after the
enclosing function exited (the D situation until some releases ago), or
making copies of outer variables.
Still, altough this closure semantics is not as 100% "full" as other
languages (latest D, C#, Lisps, etc.) it's still useful enough for C++,
and I'm surprised how relatively cleanly it fit in, unlike several of
the other extensions which seem like ugly and crufty additions.
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d-announce
mailing list