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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 return o.Take(); | 455 return o.Take(); |
456 } | 456 } |
457 | 457 |
458 // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a | 458 // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a |
459 // method. It is used internally by Bind() to select the correct | 459 // method. It is used internally by Bind() to select the correct |
460 // InvokeHelper that will no-op itself in the event the WeakPtr<> for | 460 // InvokeHelper that will no-op itself in the event the WeakPtr<> for |
461 // the target object is invalidated. | 461 // the target object is invalidated. |
462 // | 462 // |
463 // The first argument should be the type of the object that will be received by | 463 // The first argument should be the type of the object that will be received by |
464 // the method. | 464 // the method. |
465 template <bool IsMethod, typename... Args> | 465 template <bool is_method, typename... Args> |
466 struct IsWeakMethod : std::false_type {}; | 466 struct IsWeakMethod : std::false_type {}; |
467 | 467 |
468 template <typename T, typename... Args> | 468 template <typename T, typename... Args> |
469 struct IsWeakMethod<true, T, Args...> : IsWeakReceiver<T> {}; | 469 struct IsWeakMethod<true, T, Args...> : IsWeakReceiver<T> {}; |
470 | 470 |
471 // Packs a list of types to hold them in a single type. | 471 // Packs a list of types to hold them in a single type. |
472 template <typename... Types> | 472 template <typename... Types> |
473 struct TypeList {}; | 473 struct TypeList {}; |
474 | 474 |
475 // Used for DropTypeListItem implementation. | 475 // Used for DropTypeListItem implementation. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 // MSVC 2013 doesn't support Type Alias of function types. | 542 // MSVC 2013 doesn't support Type Alias of function types. |
543 // Revisit this after we update it to newer version. | 543 // Revisit this after we update it to newer version. |
544 typedef R Type(Args...); | 544 typedef R Type(Args...); |
545 }; | 545 }; |
546 | 546 |
547 // A type-level function that constructs a function type that has |R| as its | 547 // A type-level function that constructs a function type that has |R| as its |
548 // return type and has TypeLists items as its arguments. | 548 // return type and has TypeLists items as its arguments. |
549 template <typename R, typename ArgList> | 549 template <typename R, typename ArgList> |
550 using MakeFunctionType = typename MakeFunctionTypeImpl<R, ArgList>::Type; | 550 using MakeFunctionType = typename MakeFunctionTypeImpl<R, ArgList>::Type; |
551 | 551 |
552 // Used for ExtractArgs. | 552 // Used for ExtractArgs and ExtractReturnType. |
553 template <typename Signature> | 553 template <typename Signature> |
554 struct ExtractArgsImpl; | 554 struct ExtractArgsImpl; |
555 | 555 |
556 template <typename R, typename... Args> | 556 template <typename R, typename... Args> |
557 struct ExtractArgsImpl<R(Args...)> { | 557 struct ExtractArgsImpl<R(Args...)> { |
558 using Type = TypeList<Args...>; | 558 using ReturnType = R; |
| 559 using ArgsList = TypeList<Args...>; |
559 }; | 560 }; |
560 | 561 |
561 // A type-level function that extracts function arguments into a TypeList. | 562 // A type-level function that extracts function arguments into a TypeList. |
562 // E.g. ExtractArgs<R(A, B, C)> is evaluated to TypeList<A, B, C>. | 563 // E.g. ExtractArgs<R(A, B, C)> is evaluated to TypeList<A, B, C>. |
563 template <typename Signature> | 564 template <typename Signature> |
564 using ExtractArgs = typename ExtractArgsImpl<Signature>::Type; | 565 using ExtractArgs = typename ExtractArgsImpl<Signature>::ArgsList; |
| 566 |
| 567 // A type-level function that extracts the return type of a function. |
| 568 // E.g. ExtractReturnType<R(A, B, C)> is evaluated to R. |
| 569 template <typename Signature> |
| 570 using ExtractReturnType = typename ExtractArgsImpl<Signature>::ReturnType; |
565 | 571 |
566 } // namespace internal | 572 } // namespace internal |
567 | 573 |
568 template <typename T> | 574 template <typename T> |
569 static inline internal::UnretainedWrapper<T> Unretained(T* o) { | 575 static inline internal::UnretainedWrapper<T> Unretained(T* o) { |
570 return internal::UnretainedWrapper<T>(o); | 576 return internal::UnretainedWrapper<T>(o); |
571 } | 577 } |
572 | 578 |
573 template <typename T> | 579 template <typename T> |
574 static inline internal::RetainedRefWrapper<T> RetainedRef(T* o) { | 580 static inline internal::RetainedRefWrapper<T> RetainedRef(T* o) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 | 648 |
643 template <typename T> | 649 template <typename T> |
644 struct IsWeakReceiver<internal::ConstRefWrapper<T>> : IsWeakReceiver<T> {}; | 650 struct IsWeakReceiver<internal::ConstRefWrapper<T>> : IsWeakReceiver<T> {}; |
645 | 651 |
646 template <typename T> | 652 template <typename T> |
647 struct IsWeakReceiver<WeakPtr<T>> : std::true_type {}; | 653 struct IsWeakReceiver<WeakPtr<T>> : std::true_type {}; |
648 | 654 |
649 } // namespace base | 655 } // namespace base |
650 | 656 |
651 #endif // BASE_BIND_HELPERS_H_ | 657 #endif // BASE_BIND_HELPERS_H_ |
OLD | NEW |