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 #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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 // BindsArrayToFirstArg selects true_type when |is_method| is true and the first | 98 // BindsArrayToFirstArg selects true_type when |is_method| is true and the first |
99 // item of |Args| is an array type. | 99 // item of |Args| is an array type. |
100 // Implementation note: This non-specialized case handles !is_method case and | 100 // Implementation note: This non-specialized case handles !is_method case and |
101 // zero-arity case only. Other cases should be handled by the specialization | 101 // zero-arity case only. Other cases should be handled by the specialization |
102 // below. | 102 // below. |
103 template <bool is_method, typename... Args> | 103 template <bool is_method, typename... Args> |
104 struct BindsArrayToFirstArg : false_type {}; | 104 struct BindsArrayToFirstArg : false_type {}; |
105 | 105 |
106 template <typename T, typename... Args> | 106 template <typename T, typename... Args> |
107 struct BindsArrayToFirstArg<true, T, Args...> | 107 struct BindsArrayToFirstArg<true, T, Args...> : is_array<T> {}; |
108 : is_array<typename std::remove_reference<T>::type> {}; | |
109 | 108 |
110 // HasRefCountedParamAsRawPtr is the same to HasRefCountedTypeAsRawPtr except | 109 // HasRefCountedParamAsRawPtr is the same to HasRefCountedTypeAsRawPtr except |
111 // when |is_method| is true HasRefCountedParamAsRawPtr skips the first argument. | 110 // when |is_method| is true HasRefCountedParamAsRawPtr skips the first argument. |
112 // Implementation note: This non-specialized case handles !is_method case and | 111 // Implementation note: This non-specialized case handles !is_method case and |
113 // zero-arity case only. Other cases should be handled by the specialization | 112 // zero-arity case only. Other cases should be handled by the specialization |
114 // below. | 113 // below. |
115 template <bool is_method, typename... Args> | 114 template <bool is_method, typename... Args> |
116 struct HasRefCountedParamAsRawPtr : HasRefCountedTypeAsRawPtr<Args...> {}; | 115 struct HasRefCountedParamAsRawPtr : HasRefCountedTypeAsRawPtr<Args...> {}; |
117 | 116 |
118 template <typename T, typename... Args> | 117 template <typename T, typename... Args> |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 using InvokeHelperType = | 394 using InvokeHelperType = |
396 InvokeHelper<IsWeakCall::value, R, Runnable, InvokeHelperArgs>; | 395 InvokeHelper<IsWeakCall::value, R, Runnable, InvokeHelperArgs>; |
397 | 396 |
398 using UnboundArgs = DropTypeListItem<sizeof...(BoundArgs), TypeList<Args...>>; | 397 using UnboundArgs = DropTypeListItem<sizeof...(BoundArgs), TypeList<Args...>>; |
399 | 398 |
400 public: | 399 public: |
401 using InvokerType = Invoker<BoundIndices, StorageType, Unwrappers, | 400 using InvokerType = Invoker<BoundIndices, StorageType, Unwrappers, |
402 InvokeHelperType, UnboundForwardRunType>; | 401 InvokeHelperType, UnboundForwardRunType>; |
403 using UnboundRunType = MakeFunctionType<R, UnboundArgs>; | 402 using UnboundRunType = MakeFunctionType<R, UnboundArgs>; |
404 | 403 |
405 template <typename... ForwardArgs> | 404 BindState(const Runnable& runnable, const BoundArgs&... bound_args) |
406 BindState(const Runnable& runnable, ForwardArgs&&... bound_args) | |
407 : BindStateBase(&Destroy), | 405 : BindStateBase(&Destroy), |
408 runnable_(runnable), | 406 runnable_(runnable), |
409 ref_(bound_args...), | 407 ref_(bound_args...), |
410 bound_args_(std::forward<ForwardArgs>(bound_args)...) {} | 408 bound_args_(bound_args...) {} |
411 | 409 |
412 RunnableType runnable_; | 410 RunnableType runnable_; |
413 MaybeScopedRefPtr<HasIsMethodTag<Runnable>::value, BoundArgs...> ref_; | 411 MaybeScopedRefPtr<HasIsMethodTag<Runnable>::value, BoundArgs...> ref_; |
414 Tuple<BoundArgs...> bound_args_; | 412 Tuple<BoundArgs...> bound_args_; |
415 | 413 |
416 private: | 414 private: |
417 ~BindState() {} | 415 ~BindState() {} |
418 | 416 |
419 static void Destroy(BindStateBase* self) { | 417 static void Destroy(BindStateBase* self) { |
420 delete static_cast<BindState*>(self); | 418 delete static_cast<BindState*>(self); |
421 } | 419 } |
422 }; | 420 }; |
423 | 421 |
424 } // namespace internal | 422 } // namespace internal |
425 } // namespace base | 423 } // namespace base |
426 | 424 |
427 #endif // BASE_BIND_INTERNAL_H_ | 425 #endif // BASE_BIND_INTERNAL_H_ |
OLD | NEW |