DescriptionWIP: base::Bind for rvalue references.
This enables binding move-only types to callbacks without the use of
PassedWrapper. That is,
Bind(&Func, std::move(move_only_value)) or
Bind(&Func, MakeMoveOnlyValue()) would be usable instead of
Bind(&Func, Passed(&move_only_value)) or
Bind(&Func, Passed(MakeMoveOnlyValue())).
Additionally, a copyable and movable type can be moved into the callback
instead of being copied.
It has some known limitations:
(1) When invoking a callback, a bound value that is movable and copyable
will always be passed by const reference, never by rvalue reference.
(2) Movable and copyable parameters passed to Run() will be passed by
const reference, never by rvalue reference.
(3) When a move-only value is bound, there is no checking that the
callback is only run once.
(4) Callbacks with move-only bound values are copyable.
The following is speculation on how these limitations may be addressed.
(1) and (2) require some way of expressing the intent to move the value
rather than passing a const reference. For (1) it could be another
wrapper like PassedWrapper or in the longer term some way of indicating
that the callback is single-shot. For (2) it could be encoded in the
type of the callback, e.g. Callback<void(Foo)> would take a const Foo&,
but Callback<void(Foo&&)> would take a Foo&&.
(3) should be relatively straightforward to implement as a runtime
check.
(4) is unchanged from the current behaviour and would require
non-trivial changes to the current API to fix, as would enforcing (3) at
compile time.
Patch Set 1 #Patch Set 2 : #
Messages
Total messages: 3 (2 generated)
|