[cfe-dev] blocks and lambdas

Bruno Santos bsantos at av.it.pt
Thu Feb 10 13:18:17 PST 2011

Qui, 2011-02-10 às 12:44 -0800, James Gregurich escreveu:
> On Feb 10, 2011, at 12:35 PM, Bruno Santos wrote:
> > 
> > The problem is the "set of captured items". If a lambda does not capture
> > any items it can be used as a function pointer, I don't think you can do
> > that with a block since it carries baggage with it even if you don't
> > capture items. It would also violate one of the fundamental design
> > philosophies behind C++: "you don't pay for what you don't use".
> > 
> fair enough. but, you can still provide for automatic conversion in cases where one wants to feed a lambda to libdispatch or some some cocoa/foundation class. As I said earlier in this thread...if you can make that happen, I'll be happy.
> The goal that I'm lobbying for is to allow 3rd party mac developers to keep as much of their code in standard syntax and built upon standard libs as possible. Not only does it make the lives of existing mac developers easier, but it lowers the barrier to developers from other platforms to come to the mac.

You can write a generic warper that adapts a function object (a lambda)
to a block. This can be done in a very generic way with the powerful
metaprograming capabilities of C++. Just have a look at Boost.Function
and Boost.Bind.
Once you have your warper it will be trivial to adapt a lambda to a
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5428 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110210/53c1db08/attachment.bin>

More information about the cfe-dev mailing list