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

Side by Side 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, 9 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 unified diff | Download patch
« no previous file with comments | « base/bind_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_CALLBACK_H_ 5 #ifndef BASE_CALLBACK_H_
6 #define BASE_CALLBACK_H_ 6 #define BASE_CALLBACK_H_
7 7
8 #include "base/callback_forward.h" 8 #include "base/callback_forward.h"
9 #include "base/callback_internal.h" 9 #include "base/callback_internal.h"
10 #include "base/template_util.h" 10 #include "base/template_util.h"
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 PolymorphicInvoke invoke_func = 379 PolymorphicInvoke invoke_func =
380 &internal::BindState<Runnable, BindRunType, BoundArgsType...> 380 &internal::BindState<Runnable, BindRunType, BoundArgsType...>
381 ::InvokerType::Run; 381 ::InvokerType::Run;
382 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); 382 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func);
383 } 383 }
384 384
385 bool Equals(const Callback& other) const { 385 bool Equals(const Callback& other) const {
386 return CallbackBase::Equals(other); 386 return CallbackBase::Equals(other);
387 } 387 }
388 388
389 R Run(typename internal::CallbackParamTraits<Args>::ForwardType... args) 389 // Run() makes an extra copy of an argument comparing to the direct call
390 const { 390 // 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.
391 // I.e. below copies CopyableNonMovableType twice.
dcheng 2016/03/02 23:00:57 Nit: i.e.
tzik 2016/03/03 18:53:19 Done.
392 // void F(CopyableNonMovableType) {}
393 // Bind(&F).Run(CopyableNonMovableType());
394 //
395 // We can not fully apply Perfect Forwarding idiom to the callchain from
396 // Callback::Run() to the target function. Perfect Forwarding requires the
397 // information how the caller passed the argument, but we have to fix the type
398 // 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
399 R Run(Args... args) const {
391 PolymorphicInvoke f = 400 PolymorphicInvoke f =
392 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); 401 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_);
393 402 return f(bind_state_.get(), std::forward<Args>(args)...);
394 return f(bind_state_.get(), internal::CallbackForward(args)...);
395 } 403 }
396 404
397 private: 405 private:
398 using PolymorphicInvoke = 406 using PolymorphicInvoke = R (*)(internal::BindStateBase*, Args&&...);
399 R(*)(internal::BindStateBase*,
400 typename internal::CallbackParamTraits<Args>::ForwardType...);
401 }; 407 };
402 408
403 } // namespace base 409 } // namespace base
404 410
405 #endif // BASE_CALLBACK_H_ 411 #endif // BASE_CALLBACK_H_
OLDNEW
« 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