Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Issue 1498973002: WIP: base::Bind for rvalue references. (Closed)

Created:
5 years ago by Sam McNally
Modified:
4 years, 10 months ago
Reviewers:
danakj
CC:
chromium-reviews, feature-media-reviews_chromium.org, vmpstr+watch_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

WIP: 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 : #

Unified diffs Side-by-side diffs Delta from patch set Stats (+214 lines, -52 lines) Patch
M base/bind.h View 2 chunks +5 lines, -6 lines 0 comments Download
M base/bind_helpers.h View 1 chunk +21 lines, -1 line 0 comments Download
M base/bind_internal.h View 9 chunks +31 lines, -22 lines 0 comments Download
M base/bind_internal_win.h View 2 chunks +6 lines, -4 lines 0 comments Download
M base/bind_unittest.cc View 1 4 chunks +103 lines, -4 lines 0 comments Download
M base/callback.h View 1 chunk +4 lines, -4 lines 0 comments Download
M base/callback_internal.h View 4 chunks +30 lines, -10 lines 0 comments Download
M base/template_util.h View 2 chunks +13 lines, -0 lines 0 comments Download
M media/base/stream_parser.h View 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 3 (2 generated)
danakj
5 years ago (2015-12-04 22:21:12 UTC) #2
putting this in my inbox

Powered by Google App Engine
This is Rietveld 408576698