[cfe-dev] blocks with c++ lambas

Eli Friedman eli.friedman at gmail.com
Mon Sep 10 19:42:28 PDT 2012


On Mon, Sep 10, 2012 at 7:40 PM, James Gregurich <bayoubengal at me.com> wrote:
> On Sep 10, 2012, at 7:39 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
>
>> On Mon, Sep 10, 2012 at 7:26 PM, James Gregurich <bayoubengal at me.com> wrote:
>>> some time back I submitted a request to enable GCD to accept C++ lambda functions.  I got notice from apple that it was implemented in Xcode 4.4. I finally decided to try it out. I don't see how to make it work. it doesn't compile. I don't see any new dispatch functions that would accept them. I'm not finding any useful info on the web.
>>>
>>> Could I get a hint as to how to set up a dispatch call using a C++ lambda with clang and libc++?
>>
>> Make sure you're compiling in Objective-C++ mode.
> just pass it as is to dispatch_async()?

Yes.  Short example:

#include <dispatch/dispatch.h>
#include <cstdio>
dispatch_once_t once;
int main() {
  dispatch_once(&once, []{printf("asdf\n");});
}

-Eli




More information about the cfe-dev mailing list