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

Side by Side Diff: base/bind_internal.h

Issue 1709483002: Support move-only type on base::Callback::Run (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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_helpers.h ('k') | base/bind_unittest.cc » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_BIND_INTERNAL_H_ 5 #ifndef BASE_BIND_INTERNAL_H_
6 #define BASE_BIND_INTERNAL_H_ 6 #define BASE_BIND_INTERNAL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <type_traits> 10 #include <type_traits>
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // 332 //
333 // See description at the top of the file. 333 // See description at the top of the file.
334 template <typename BoundIndices, typename StorageType, 334 template <typename BoundIndices, typename StorageType,
335 typename InvokeHelperType, typename UnboundForwardRunType> 335 typename InvokeHelperType, typename UnboundForwardRunType>
336 struct Invoker; 336 struct Invoker;
337 337
338 template <size_t... bound_indices, 338 template <size_t... bound_indices,
339 typename StorageType, 339 typename StorageType,
340 typename InvokeHelperType, 340 typename InvokeHelperType,
341 typename R, 341 typename R,
342 typename... UnboundForwardArgs> 342 typename... UnboundArgs>
343 struct Invoker<IndexSequence<bound_indices...>, StorageType, 343 struct Invoker<IndexSequence<bound_indices...>,
344 InvokeHelperType, R(UnboundForwardArgs...)> { 344 StorageType,
345 static R Run(BindStateBase* base, 345 InvokeHelperType,
346 UnboundForwardArgs... unbound_args) { 346 R(UnboundArgs...)> {
347 static R Run(BindStateBase* base, UnboundArgs&&... unbound_args) {
347 StorageType* storage = static_cast<StorageType*>(base); 348 StorageType* storage = static_cast<StorageType*>(base);
348 // Local references to make debugger stepping easier. If in a debugger, 349 // Local references to make debugger stepping easier. If in a debugger,
349 // you really want to warp ahead and step through the 350 // you really want to warp ahead and step through the
350 // InvokeHelper<>::MakeItSo() call below. 351 // InvokeHelper<>::MakeItSo() call below.
351 return InvokeHelperType::MakeItSo( 352 return InvokeHelperType::MakeItSo(
352 storage->runnable_, 353 storage->runnable_, Unwrap(get<bound_indices>(storage->bound_args_))...,
353 Unwrap(get<bound_indices>(storage->bound_args_))..., 354 std::forward<UnboundArgs>(unbound_args)...);
354 CallbackForward(unbound_args)...);
355 } 355 }
356 }; 356 };
357 357
358 // Used to implement MakeArgsStorage. 358 // Used to implement MakeArgsStorage.
359 template <bool is_method, typename... BoundArgs> 359 template <bool is_method, typename... BoundArgs>
360 struct MakeArgsStorageImpl { 360 struct MakeArgsStorageImpl {
361 using Type = std::tuple<BoundArgs...>; 361 using Type = std::tuple<BoundArgs...>;
362 }; 362 };
363 363
364 template <typename Obj, typename... BoundArgs> 364 template <typename Obj, typename... BoundArgs>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 using RunnableType = Runnable; 399 using RunnableType = Runnable;
400 400
401 enum { is_method = HasIsMethodTag<Runnable>::value }; 401 enum { is_method = HasIsMethodTag<Runnable>::value };
402 402
403 // true_type if Runnable is a method invocation and the first bound argument 403 // true_type if Runnable is a method invocation and the first bound argument
404 // is a WeakPtr. 404 // is a WeakPtr.
405 using IsWeakCall = 405 using IsWeakCall =
406 IsWeakMethod<is_method, typename std::decay<BoundArgs>::type...>; 406 IsWeakMethod<is_method, typename std::decay<BoundArgs>::type...>;
407 407
408 using BoundIndices = MakeIndexSequence<sizeof...(BoundArgs)>; 408 using BoundIndices = MakeIndexSequence<sizeof...(BoundArgs)>;
409 using UnboundForwardArgs = DropTypeListItem<
410 sizeof...(BoundArgs),
411 TypeList<typename CallbackParamTraits<Args>::ForwardType...>>;
412 using UnboundForwardRunType = MakeFunctionType<R, UnboundForwardArgs>;
413 using InvokeHelperType = InvokeHelper<IsWeakCall::value, R, Runnable>; 409 using InvokeHelperType = InvokeHelper<IsWeakCall::value, R, Runnable>;
414 410
415 using UnboundArgs = DropTypeListItem<sizeof...(BoundArgs), TypeList<Args...>>; 411 using UnboundArgs = DropTypeListItem<sizeof...(BoundArgs), TypeList<Args...>>;
416 412
417 public: 413 public:
418 using InvokerType = Invoker<BoundIndices, StorageType,
419 InvokeHelperType, UnboundForwardRunType>;
420 using UnboundRunType = MakeFunctionType<R, UnboundArgs>; 414 using UnboundRunType = MakeFunctionType<R, UnboundArgs>;
415 using InvokerType =
416 Invoker<BoundIndices, StorageType, InvokeHelperType, UnboundRunType>;
421 417
422 template <typename... ForwardArgs> 418 template <typename... ForwardArgs>
423 BindState(const Runnable& runnable, ForwardArgs&&... bound_args) 419 BindState(const Runnable& runnable, ForwardArgs&&... bound_args)
424 : BindStateBase(&Destroy), 420 : BindStateBase(&Destroy),
425 runnable_(runnable), 421 runnable_(runnable),
426 bound_args_(std::forward<ForwardArgs>(bound_args)...) {} 422 bound_args_(std::forward<ForwardArgs>(bound_args)...) {}
427 423
428 RunnableType runnable_; 424 RunnableType runnable_;
429 MakeArgsStorage<is_method, BoundArgs...> bound_args_; 425 MakeArgsStorage<is_method, BoundArgs...> bound_args_;
430 426
431 private: 427 private:
432 ~BindState() {} 428 ~BindState() {}
433 429
434 static void Destroy(BindStateBase* self) { 430 static void Destroy(BindStateBase* self) {
435 delete static_cast<BindState*>(self); 431 delete static_cast<BindState*>(self);
436 } 432 }
437 }; 433 };
438 434
439 } // namespace internal 435 } // namespace internal
440 } // namespace base 436 } // namespace base
441 437
442 #endif // BASE_BIND_INTERNAL_H_ 438 #endif // BASE_BIND_INTERNAL_H_
OLDNEW
« no previous file with comments | « base/bind_helpers.h ('k') | base/bind_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698