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

Side by Side Diff: base/bind_internal.h

Issue 1774443002: Replace template_util.h stuff with C++11 <type_traits> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert unrelated whitespace change 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/callback.h » ('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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 // Invoker<> -- Unwraps the curried parameters and executes the Runnable. 61 // Invoker<> -- Unwraps the curried parameters and executes the Runnable.
62 // BindState<> -- Stores the curried parameters, and is the main entry point 62 // BindState<> -- Stores the curried parameters, and is the main entry point
63 // into the Bind() system, doing most of the type resolution. 63 // into the Bind() system, doing most of the type resolution.
64 // There are ARITY BindState types. 64 // There are ARITY BindState types.
65 65
66 // HasNonConstReferenceParam selects true_type when any of the parameters in 66 // HasNonConstReferenceParam selects true_type when any of the parameters in
67 // |Sig| is a non-const reference. 67 // |Sig| is a non-const reference.
68 // Implementation note: This non-specialized case handles zero-arity case only. 68 // Implementation note: This non-specialized case handles zero-arity case only.
69 // Non-zero-arity cases should be handled by the specialization below. 69 // Non-zero-arity cases should be handled by the specialization below.
70 template <typename List> 70 template <typename List>
71 struct HasNonConstReferenceItem : false_type {}; 71 struct HasNonConstReferenceItem : std::false_type {};
72 72
73 // Implementation note: Select true_type if the first parameter is a non-const 73 // Implementation note: Select true_type if the first parameter is a non-const
74 // reference. Otherwise, skip the first parameter and check rest of parameters 74 // reference. Otherwise, skip the first parameter and check rest of parameters
75 // recursively. 75 // recursively.
76 template <typename T, typename... Args> 76 template <typename T, typename... Args>
77 struct HasNonConstReferenceItem<TypeList<T, Args...>> 77 struct HasNonConstReferenceItem<TypeList<T, Args...>>
78 : std::conditional<is_non_const_reference<T>::value, 78 : std::conditional<is_non_const_reference<T>::value,
79 true_type, 79 std::true_type,
80 HasNonConstReferenceItem<TypeList<Args...>>>::type {}; 80 HasNonConstReferenceItem<TypeList<Args...>>>::type {};
81 81
82 // HasRefCountedTypeAsRawPtr selects true_type when any of the |Args| is a raw 82 // HasRefCountedTypeAsRawPtr selects true_type when any of the |Args| is a raw
83 // pointer to a RefCounted type. 83 // pointer to a RefCounted type.
84 // Implementation note: This non-specialized case handles zero-arity case only. 84 // Implementation note: This non-specialized case handles zero-arity case only.
85 // Non-zero-arity cases should be handled by the specialization below. 85 // Non-zero-arity cases should be handled by the specialization below.
86 template <typename... Args> 86 template <typename... Args>
87 struct HasRefCountedTypeAsRawPtr : false_type {}; 87 struct HasRefCountedTypeAsRawPtr : std::false_type {};
88 88
89 // Implementation note: Select true_type if the first parameter is a raw pointer 89 // Implementation note: Select true_type if the first parameter is a raw pointer
90 // to a RefCounted type. Otherwise, skip the first parameter and check rest of 90 // to a RefCounted type. Otherwise, skip the first parameter and check rest of
91 // parameters recursively. 91 // parameters recursively.
92 template <typename T, typename... Args> 92 template <typename T, typename... Args>
93 struct HasRefCountedTypeAsRawPtr<T, Args...> 93 struct HasRefCountedTypeAsRawPtr<T, Args...>
94 : std::conditional<NeedsScopedRefptrButGetsRawPtr<T>::value, 94 : std::conditional<NeedsScopedRefptrButGetsRawPtr<T>::value,
95 true_type, 95 std::true_type,
96 HasRefCountedTypeAsRawPtr<Args...>>::type {}; 96 HasRefCountedTypeAsRawPtr<Args...>>::type {};
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 : std::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...>
108 : is_array<typename std::remove_reference<T>::type> {}; 108 : std::is_array<typename std::remove_reference<T>::type> {};
109 109
110 // HasRefCountedParamAsRawPtr is the same to HasRefCountedTypeAsRawPtr except 110 // HasRefCountedParamAsRawPtr is the same to HasRefCountedTypeAsRawPtr except
111 // when |is_method| is true HasRefCountedParamAsRawPtr skips the first argument. 111 // when |is_method| is true HasRefCountedParamAsRawPtr skips the first argument.
112 // Implementation note: This non-specialized case handles !is_method case and 112 // Implementation note: This non-specialized case handles !is_method case and
113 // zero-arity case only. Other cases should be handled by the specialization 113 // zero-arity case only. Other cases should be handled by the specialization
114 // below. 114 // below.
115 template <bool is_method, typename... Args> 115 template <bool is_method, typename... Args>
116 struct HasRefCountedParamAsRawPtr : HasRefCountedTypeAsRawPtr<Args...> {}; 116 struct HasRefCountedParamAsRawPtr : HasRefCountedTypeAsRawPtr<Args...> {};
117 117
118 template <typename T, typename... Args> 118 template <typename T, typename... Args>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 R (*function_)(Args...); 163 R (*function_)(Args...);
164 }; 164 };
165 165
166 // Method. 166 // Method.
167 template <typename R, typename T, typename... Args> 167 template <typename R, typename T, typename... Args>
168 class RunnableAdapter<R(T::*)(Args...)> { 168 class RunnableAdapter<R(T::*)(Args...)> {
169 public: 169 public:
170 // MSVC 2013 doesn't support Type Alias of function types. 170 // MSVC 2013 doesn't support Type Alias of function types.
171 // Revisit this after we update it to newer version. 171 // Revisit this after we update it to newer version.
172 typedef R RunType(T*, Args...); 172 typedef R RunType(T*, Args...);
173 using IsMethod = true_type; 173 using IsMethod = std::true_type;
174 174
175 explicit RunnableAdapter(R(T::*method)(Args...)) 175 explicit RunnableAdapter(R(T::*method)(Args...))
176 : method_(method) { 176 : method_(method) {
177 } 177 }
178 178
179 template <typename... RunArgs> 179 template <typename... RunArgs>
180 R Run(T* object, RunArgs&&... args) { 180 R Run(T* object, RunArgs&&... args) {
181 return (object->*method_)(std::forward<RunArgs>(args)...); 181 return (object->*method_)(std::forward<RunArgs>(args)...);
182 } 182 }
183 183
184 private: 184 private:
185 R (T::*method_)(Args...); 185 R (T::*method_)(Args...);
186 }; 186 };
187 187
188 // Const Method. 188 // Const Method.
189 template <typename R, typename T, typename... Args> 189 template <typename R, typename T, typename... Args>
190 class RunnableAdapter<R(T::*)(Args...) const> { 190 class RunnableAdapter<R(T::*)(Args...) const> {
191 public: 191 public:
192 using RunType = R(const T*, Args...); 192 using RunType = R(const T*, Args...);
193 using IsMethod = true_type; 193 using IsMethod = std::true_type;
194 194
195 explicit RunnableAdapter(R(T::*method)(Args...) const) 195 explicit RunnableAdapter(R(T::*method)(Args...) const)
196 : method_(method) { 196 : method_(method) {
197 } 197 }
198 198
199 template <typename... RunArgs> 199 template <typename... RunArgs>
200 R Run(const T* object, RunArgs&&... args) { 200 R Run(const T* object, RunArgs&&... args) {
201 return (object->*method_)(std::forward<RunArgs>(args)...); 201 return (object->*method_)(std::forward<RunArgs>(args)...);
202 } 202 }
203 203
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 315 }
316 }; 316 };
317 317
318 #if !defined(_MSC_VER) 318 #if !defined(_MSC_VER)
319 319
320 template <typename ReturnType, typename Runnable> 320 template <typename ReturnType, typename Runnable>
321 struct InvokeHelper<true, ReturnType, Runnable> { 321 struct InvokeHelper<true, ReturnType, Runnable> {
322 // WeakCalls are only supported for functions with a void return type. 322 // WeakCalls are only supported for functions with a void return type.
323 // Otherwise, the function result would be undefined if the the WeakPtr<> 323 // Otherwise, the function result would be undefined if the the WeakPtr<>
324 // is invalidated. 324 // is invalidated.
325 static_assert(is_void<ReturnType>::value, 325 static_assert(std::is_void<ReturnType>::value,
326 "weak_ptrs can only bind to methods without return values"); 326 "weak_ptrs can only bind to methods without return values");
327 }; 327 };
328 328
329 #endif 329 #endif
330 330
331 // Invoker<> 331 // Invoker<>
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>
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 433
434 static void Destroy(BindStateBase* self) { 434 static void Destroy(BindStateBase* self) {
435 delete static_cast<BindState*>(self); 435 delete static_cast<BindState*>(self);
436 } 436 }
437 }; 437 };
438 438
439 } // namespace internal 439 } // namespace internal
440 } // namespace base 440 } // namespace base
441 441
442 #endif // BASE_BIND_INTERNAL_H_ 442 #endif // BASE_BIND_INTERNAL_H_
OLDNEW
« no previous file with comments | « base/bind_helpers.h ('k') | base/callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698