C++0x now with lambda and closure

Sean Kelly sean at invisibleduck.org
Mon Mar 31 16:46:06 PDT 2008


== Quote from guslay (guslay at gmail.com)'s article
> For those keeping track...
> http://herbsutter.spaces.live.com/
> Crazy syntax, at least it looks better than boost.

Pretty cool, but still not as nice as D's delegates.  From the
proposal (5.1.1): "Each lambda expression has a  unique type.
Except as specified below, the type of the closure object is
unspecified."  This suggests that a closure really isn't intended
to escape the scope in which it is declared, because there's
no easy way to declare one (I can imagine some fancy template
tricks to do so, but I'm ignoring them).

This is actually somewhat interesting because the syntax for
declaring closures in C++ seems to allow for this by providing
a way for automatic local data to be saved (the capture list).
Perhaps they'll get another shot in the arm in the next iteration
of C++ to become more like full closures.  Or maybe this was
enough of a language change and the rest is expected to be
taken care of in library code?  I haven't been following the
progress of 0x in the past year or two so I really couldn't
say what the reasoning is here.

Interestingly, this proposal Herb mentions has removed 'auto' as
a storage class:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2546.htm

This seems completely unnecessary to me--the D way makes much
more sense.  Simply omit the type portion of the declaration and the
type is inferred.  I wonder what the reasoning was here?

It's kind of weird, but now that the new spec is basically finalized I
find myself having trouble finding many features that I'm actually
enthusiastic about.  Most of the few features that sound really cool in
theory already exist in D and their syntax there is much nicer.  And
some of the proposals are such obvious extensions of other proposals
that their existence simply stands as a testament to the bureaucracy
involved in the standardization process.  This one, for example:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2547.htm

After more than sixteen years with the language it feels strange to
say that I actually feel somewhat relieved that my professional
work has led me away from C++ recently.


Sean


More information about the Digitalmars-d-announce mailing list