[cfe-dev] blocks and lambdas
bayoubengal at mac.com
Mon Feb 7 18:33:06 PST 2011
What if you build your lambda structure around the existing block structure such that the lambda type would have a copy constructor that calls Block_copy? If the lambda has a type, it stands to reason that it could have a copy constructor.
On Feb 7, 2011, at 5:35 PM, John McCall wrote:
> On Feb 7, 2011, at 5:24 PM, James Gregurich wrote:
>> Is that because Block_copy is changing retain counts on captured values?
> No, it's because block literals are initially allocated on the stack, so if you
> return out of that stack frame, the block pointer becomes a dangling reference.
> You could get the same result by passing a C++0x lambda around by
> reference or pointer.
> The problem is that generic code written for '0x lambdas will often assume that
> copying a function object by value does a deep copy; however, copying a
> block pointer is really just a pointer "copy", and the deep copy operation has
> to be invoked manually.
More information about the cfe-dev