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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 | 520 |
521 template <> | 521 template <> |
522 struct DropTypeListItemImpl<0, TypeList<>> { | 522 struct DropTypeListItemImpl<0, TypeList<>> { |
523 typedef TypeList<> Type; | 523 typedef TypeList<> Type; |
524 }; | 524 }; |
525 | 525 |
526 // A type-level function that drops |n| list item from given TypeList. | 526 // A type-level function that drops |n| list item from given TypeList. |
527 template <size_t n, typename List> | 527 template <size_t n, typename List> |
528 using DropTypeListItem = typename DropTypeListItemImpl<n, List>::Type; | 528 using DropTypeListItem = typename DropTypeListItemImpl<n, List>::Type; |
529 | 529 |
530 // Used for TakeTypeListItem implementation. | |
531 template <size_t n, typename List, typename... Accum> | |
532 struct TakeTypeListItemImpl; | |
533 | |
534 // Do not use enable_if and SFINAE here to avoid MSVC2013 compile failure. | |
535 template <size_t n, typename T, typename... List, typename... Accum> | |
536 struct TakeTypeListItemImpl<n, TypeList<T, List...>, Accum...> | |
537 : TakeTypeListItemImpl<n - 1, TypeList<List...>, Accum..., T> {}; | |
538 | |
539 template <typename T, typename... List, typename... Accum> | |
540 struct TakeTypeListItemImpl<0, TypeList<T, List...>, Accum...> { | |
541 typedef TypeList<Accum...> Type; | |
dcheng
2015/12/14 19:26:46
Let's do using Type = TypeList<Accum...>;
tzik
2015/12/15 05:55:09
Done.
| |
542 }; | |
543 | |
544 template <typename... Accum> | |
545 struct TakeTypeListItemImpl<0, TypeList<>, Accum...> { | |
546 typedef TypeList<Accum...> Type; | |
547 }; | |
548 | |
549 // A type-level function that takes first |n| list item from given TypeList. | |
dcheng
2015/12/14 19:26:46
Can this comment include an example input and the
tzik
2015/12/15 05:55:09
Done.
| |
550 template <size_t n, typename List> | |
551 using TakeTypeListItem = typename TakeTypeListItemImpl<n, List>::Type; | |
552 | |
530 // Used for ConcatTypeLists implementation. | 553 // Used for ConcatTypeLists implementation. |
531 template <typename List1, typename List2> | 554 template <typename List1, typename List2> |
532 struct ConcatTypeListsImpl; | 555 struct ConcatTypeListsImpl; |
533 | 556 |
534 template <typename... Types1, typename... Types2> | 557 template <typename... Types1, typename... Types2> |
535 struct ConcatTypeListsImpl<TypeList<Types1...>, TypeList<Types2...>> { | 558 struct ConcatTypeListsImpl<TypeList<Types1...>, TypeList<Types2...>> { |
536 typedef TypeList<Types1..., Types2...> Type; | 559 typedef TypeList<Types1..., Types2...> Type; |
537 }; | 560 }; |
538 | 561 |
539 // A type-level function that concats two TypeLists. | 562 // A type-level function that concats two TypeLists. |
540 template <typename List1, typename List2> | 563 template <typename List1, typename List2> |
541 using ConcatTypeLists = typename ConcatTypeListsImpl<List1, List2>::Type; | 564 using ConcatTypeLists = typename ConcatTypeListsImpl<List1, List2>::Type; |
542 | 565 |
543 // Used for MakeFunctionType implementation. | 566 // Used for MakeFunctionType implementation. |
544 template <typename R, typename ArgList> | 567 template <typename R, typename ArgList> |
545 struct MakeFunctionTypeImpl; | 568 struct MakeFunctionTypeImpl; |
546 | 569 |
547 template <typename R, typename... Args> | 570 template <typename R, typename... Args> |
548 struct MakeFunctionTypeImpl<R, TypeList<Args...>> { | 571 struct MakeFunctionTypeImpl<R, TypeList<Args...>> { |
549 typedef R(Type)(Args...); | 572 typedef R(Type)(Args...); |
550 }; | 573 }; |
551 | 574 |
552 // A type-level function that constructs a function type that has |R| as its | 575 // A type-level function that constructs a function type that has |R| as its |
553 // return type and has TypeLists items as its arguments. | 576 // return type and has TypeLists items as its arguments. |
554 template <typename R, typename ArgList> | 577 template <typename R, typename ArgList> |
555 using MakeFunctionType = typename MakeFunctionTypeImpl<R, ArgList>::Type; | 578 using MakeFunctionType = typename MakeFunctionTypeImpl<R, ArgList>::Type; |
556 | 579 |
580 // Used for ExtractArgs. | |
581 template <typename Signature> | |
582 struct ExtractArgsImpl; | |
583 | |
584 template <typename R, typename... Args> | |
585 struct ExtractArgsImpl<R(Args...)> { | |
586 using Type = TypeList<Args...>; | |
587 }; | |
588 | |
589 // A type-level function that extracts function arguments into a TypeList. | |
dcheng
2015/12/14 19:26:46
Ditto:
Input: R(A1, A2, A3) => TypeList<A1, A2, A
tzik
2015/12/15 05:55:09
Done.
| |
590 template <typename Signature> | |
591 using ExtractArgs = typename ExtractArgsImpl<Signature>::Type; | |
592 | |
557 } // namespace internal | 593 } // namespace internal |
558 | 594 |
559 template <typename T> | 595 template <typename T> |
560 static inline internal::UnretainedWrapper<T> Unretained(T* o) { | 596 static inline internal::UnretainedWrapper<T> Unretained(T* o) { |
561 return internal::UnretainedWrapper<T>(o); | 597 return internal::UnretainedWrapper<T>(o); |
562 } | 598 } |
563 | 599 |
564 template <typename T> | 600 template <typename T> |
565 static inline internal::ConstRefWrapper<T> ConstRef(const T& o) { | 601 static inline internal::ConstRefWrapper<T> ConstRef(const T& o) { |
566 return internal::ConstRefWrapper<T>(o); | 602 return internal::ConstRefWrapper<T>(o); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 BASE_EXPORT void DoNothing(); | 642 BASE_EXPORT void DoNothing(); |
607 | 643 |
608 template<typename T> | 644 template<typename T> |
609 void DeletePointer(T* obj) { | 645 void DeletePointer(T* obj) { |
610 delete obj; | 646 delete obj; |
611 } | 647 } |
612 | 648 |
613 } // namespace base | 649 } // namespace base |
614 | 650 |
615 #endif // BASE_BIND_HELPERS_H_ | 651 #endif // BASE_BIND_HELPERS_H_ |
OLD | NEW |