OLD | NEW |
---|---|
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 // This defines a set of argument wrappers and related factory methods that | 5 // This defines a set of argument wrappers and related factory methods that |
6 // can be used specify the refcounting and reference semantics of arguments | 6 // can be used specify the refcounting and reference semantics of arguments |
7 // that are bound by the Bind() function in base/bind.h. | 7 // that are bound by the Bind() function in base/bind.h. |
8 // | 8 // |
9 // It also defines a set of simple functions and utilities that people want | 9 // It also defines a set of simple functions and utilities that people want |
10 // when using Callback<> and Bind(). | 10 // when using Callback<> and Bind(). |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 return o.Take(); | 451 return o.Take(); |
452 } | 452 } |
453 | 453 |
454 // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a | 454 // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a |
455 // method. It is used internally by Bind() to select the correct | 455 // method. It is used internally by Bind() to select the correct |
456 // InvokeHelper that will no-op itself in the event the WeakPtr<> for | 456 // InvokeHelper that will no-op itself in the event the WeakPtr<> for |
457 // the target object is invalidated. | 457 // the target object is invalidated. |
458 // | 458 // |
459 // The first argument should be the type of the object that will be received by | 459 // The first argument should be the type of the object that will be received by |
460 // the method. | 460 // the method. |
461 template <bool IsMethod, typename... Args> | 461 template <bool IsMethod, typename ArgsTuple> |
462 struct IsWeakMethod : public std::false_type {}; | 462 struct IsWeakMethod : std::false_type {}; |
463 | 463 |
464 template <typename T, typename... Args> | 464 template <typename T, typename... Args> |
465 struct IsWeakMethod<true, WeakPtr<T>, Args...> : public std::true_type {}; | 465 struct IsWeakMethod<true, std::tuple<WeakPtr<T>, Args...>> : std::true_type {}; |
466 | 466 |
467 template <typename T, typename... Args> | 467 template <typename T, typename... Args> |
468 struct IsWeakMethod<true, ConstRefWrapper<WeakPtr<T>>, Args...> | 468 struct IsWeakMethod<true, std::tuple<ConstRefWrapper<WeakPtr<T>>, Args...>> |
469 : public std::true_type {}; | 469 : std::true_type {}; |
470 | 470 |
471 | 471 |
472 // Packs a list of types to hold them in a single type. | 472 // Packs a list of types to hold them in a single type. |
473 template <typename... Types> | 473 template <typename... Types> |
474 struct TypeList {}; | 474 struct TypeList {}; |
475 | 475 |
476 // Used for DropTypeListItem implementation. | 476 // Used for DropTypeListItem implementation. |
477 template <size_t n, typename List> | 477 template <size_t n, typename List> |
478 struct DropTypeListItemImpl; | 478 struct DropTypeListItemImpl; |
479 | 479 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 // MSVC 2013 doesn't support Type Alias of function types. | 543 // MSVC 2013 doesn't support Type Alias of function types. |
544 // Revisit this after we update it to newer version. | 544 // Revisit this after we update it to newer version. |
545 typedef R Type(Args...); | 545 typedef R Type(Args...); |
546 }; | 546 }; |
547 | 547 |
548 // A type-level function that constructs a function type that has |R| as its | 548 // A type-level function that constructs a function type that has |R| as its |
549 // return type and has TypeLists items as its arguments. | 549 // return type and has TypeLists items as its arguments. |
550 template <typename R, typename ArgList> | 550 template <typename R, typename ArgList> |
551 using MakeFunctionType = typename MakeFunctionTypeImpl<R, ArgList>::Type; | 551 using MakeFunctionType = typename MakeFunctionTypeImpl<R, ArgList>::Type; |
552 | 552 |
553 // Used for ExtractArgs. | 553 // Used for ExtractArgs and ExtractReturnType. |
554 template <typename Signature> | 554 template <typename Signature> |
555 struct ExtractArgsImpl; | 555 struct ExtractArgsImpl; |
556 | 556 |
557 template <typename R, typename... Args> | 557 template <typename R, typename... Args> |
558 struct ExtractArgsImpl<R(Args...)> { | 558 struct ExtractArgsImpl<R(Args...)> { |
559 using Type = TypeList<Args...>; | 559 using ReturnType = R; |
560 using ArgsList = TypeList<Args...>; | |
560 }; | 561 }; |
561 | 562 |
562 // A type-level function that extracts function arguments into a TypeList. | 563 // A type-level function that extracts function arguments into a TypeList. |
563 // E.g. ExtractArgs<R(A, B, C)> is evaluated to TypeList<A, B, C>. | 564 // E.g. ExtractArgs<R(A, B, C)> is evaluated to TypeList<A, B, C>. |
564 template <typename Signature> | 565 template <typename Signature> |
565 using ExtractArgs = typename ExtractArgsImpl<Signature>::Type; | 566 using ExtractArgs = typename ExtractArgsImpl<Signature>::ArgsList; |
567 | |
568 // A type-level function that extracts return type of a function. | |
Nico
2016/06/02 17:27:44
grammar nit: "that extracts the return type of a f
tzik
2016/06/03 13:29:52
Thanks! Done.
| |
569 // E.g. ExtractReturnType<R(A, B, C)> is evaluated to R. | |
570 template <typename Signature> | |
571 using ExtractReturnType = typename ExtractArgsImpl<Signature>::ReturnType; | |
566 | 572 |
567 } // namespace internal | 573 } // namespace internal |
568 | 574 |
569 template <typename T> | 575 template <typename T> |
570 static inline internal::UnretainedWrapper<T> Unretained(T* o) { | 576 static inline internal::UnretainedWrapper<T> Unretained(T* o) { |
571 return internal::UnretainedWrapper<T>(o); | 577 return internal::UnretainedWrapper<T>(o); |
572 } | 578 } |
573 | 579 |
574 template <typename T> | 580 template <typename T> |
575 static inline internal::RetainedRefWrapper<T> RetainedRef(T* o) { | 581 static inline internal::RetainedRefWrapper<T> RetainedRef(T* o) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 BASE_EXPORT void DoNothing(); | 629 BASE_EXPORT void DoNothing(); |
624 | 630 |
625 template<typename T> | 631 template<typename T> |
626 void DeletePointer(T* obj) { | 632 void DeletePointer(T* obj) { |
627 delete obj; | 633 delete obj; |
628 } | 634 } |
629 | 635 |
630 } // namespace base | 636 } // namespace base |
631 | 637 |
632 #endif // BASE_BIND_HELPERS_H_ | 638 #endif // BASE_BIND_HELPERS_H_ |
OLD | NEW |