[cfe-dev] libcxx: std::function should be able to capture blocks

Eric Fiselier eric at efcs.ca
Thu Oct 2 21:06:17 PDT 2014


Hi All,

I through a copy of your patch up on phabricator here with some inline
comments, but for the most part it seems correct and the right way to do
things.
http://reviews.llvm.org/D5596

I'm not convinced direction all together and I'll leave that decision up to
others.
I would prefer David's suggestion and to leave libc++ unchanged, but I'm
not opposed to this change all together.

/Eric








On Wed, Oct 1, 2014 at 12:57 PM, David Blaikie <dblaikie at gmail.com> wrote:

> [+Marshall as libc++ maintainer]
>
> What would it look like if we just provided a value-semantic-C++ wrapper
> around blocks, translating C++ move/copy operations down to the
> Block_copy/release/etc operations?
>
> That way it'd be orthogonal to the type erasure of std::function and could
> be used just for a convenience when using blocks in C++ code anyway:
>
>   auto x = make_cpp_block(/* block stuff */);
>   auto y = x;
>   x();
>   etc...
>
> (& then you'd compose them with "std::function<...> f =
> make_cpp_block(...);" (the block wrapper could have an implicit conversion
> to std::function))
>
> It's a little more text, but doesn't require an extension to the standard
> library, and can be used independently.
>
> On Wed, Oct 1, 2014 at 11:38 AM, Jared Grubb <jared.grubb at gmail.com>
> wrote:
>
>> == Background:
>> std::function will wrap anything that is callable (and can be
>> copied/moved). Blocks are copyable and callable, however you need to use
>> the reference counting Block_copy/Block_release functions.
>>
>> == Request for Comment on the Patch:
>> I am working on a patch that will allow std::function to capture blocks
>> correctly (under the right feature guards).
>>
>> Functionally, the patch is complete. However, it's not checkin-ready as I
>> had a couple questions on the approach:
>>  * Is the approach right? I specialized the __func storage class, as that
>> seems to be the right thing to customize.
>>  * I have included some unit test implementations. There are quite a few
>> std::function unit tests, so I wanted to make sure I was on the right track
>> before I do all of them.
>>  * Should I add tests for ObjC++ code, under ARC and non-ARC scenarios?
>> There are no ObjC++ files in libcxx, and the test-runner does not yet
>> support them. Adding this is not hard, but it's a change in how things are
>> today.
>>
>> If this looks like it's on the right track, I will flush out the rest of
>> the unit tests, and optionally add ObjC++ unit tests.
>>
>>
>>
>>
>> Jared
>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141002/1f70af5f/attachment.html>


More information about the cfe-dev mailing list