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

Unified Diff: base/callback.h

Issue 1709483002: Support move-only type on base::Callback::Run (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +comment Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/bind_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/callback.h
diff --git a/base/callback.h b/base/callback.h
index 3bf0008b6d33bf73e075f502523327817ddb1345..46c57527a1afdd8c3ca3174a6f1f976979724662 100644
--- a/base/callback.h
+++ b/base/callback.h
@@ -386,18 +386,24 @@ class Callback<R(Args...)> : public internal::CallbackBase {
return CallbackBase::Equals(other);
}
- R Run(typename internal::CallbackParamTraits<Args>::ForwardType... args)
- const {
+ // Run() makes an extra copy of an argument comparing to the direct call
+ // if an item of |args| is passed-by-value and a copyable-but-not-movable.
dcheng 2016/03/02 23:00:57 Nit: Run() makes an extra copy compared to directl
tzik 2016/03/03 18:53:19 Done.
+ // I.e. below copies CopyableNonMovableType twice.
dcheng 2016/03/02 23:00:57 Nit: i.e.
tzik 2016/03/03 18:53:19 Done.
+ // void F(CopyableNonMovableType) {}
+ // Bind(&F).Run(CopyableNonMovableType());
+ //
+ // We can not fully apply Perfect Forwarding idiom to the callchain from
+ // Callback::Run() to the target function. Perfect Forwarding requires the
+ // information how the caller passed the argument, but we have to fix the type
+ // of |f| before we know how the arguments of Callback::Run() are passed.
dcheng 2016/03/02 23:00:57 Nit: Perfect Forwarding requires knowing how the c
tzik 2016/03/03 18:53:19 Done, but slightly modified. We can template Callb
+ R Run(Args... args) const {
PolymorphicInvoke f =
reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_);
-
- return f(bind_state_.get(), internal::CallbackForward(args)...);
+ return f(bind_state_.get(), std::forward<Args>(args)...);
}
private:
- using PolymorphicInvoke =
- R(*)(internal::BindStateBase*,
- typename internal::CallbackParamTraits<Args>::ForwardType...);
+ using PolymorphicInvoke = R (*)(internal::BindStateBase*, Args&&...);
};
} // namespace base
« no previous file with comments | « base/bind_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698