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

Side by Side Diff: base/bind_internal.h

Issue 1537553002: Replace typedef with using for Callback/Bind related files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years 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/bind_internal_win.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 <type_traits> 8 #include <type_traits>
9 9
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // IsMethod typedef is exposed. The existence of this typedef (NOT the value) 136 // IsMethod typedef is exposed. The existence of this typedef (NOT the value)
137 // marks that the wrapper should be considered a method wrapper. 137 // marks that the wrapper should be considered a method wrapper.
138 138
139 template <typename Functor> 139 template <typename Functor>
140 class RunnableAdapter; 140 class RunnableAdapter;
141 141
142 // Function. 142 // Function.
143 template <typename R, typename... Args> 143 template <typename R, typename... Args>
144 class RunnableAdapter<R(*)(Args...)> { 144 class RunnableAdapter<R(*)(Args...)> {
145 public: 145 public:
146 typedef R (RunType)(Args...); 146 // MSVC 2013 doesn't support Type Alias of function types.
147 // Revisit this after we update it to newer version.
148 typedef R RunType(Args...);
147 149
148 explicit RunnableAdapter(R(*function)(Args...)) 150 explicit RunnableAdapter(R(*function)(Args...))
149 : function_(function) { 151 : function_(function) {
150 } 152 }
151 153
152 R Run(typename CallbackParamTraits<Args>::ForwardType... args) { 154 R Run(typename CallbackParamTraits<Args>::ForwardType... args) {
153 return function_(CallbackForward(args)...); 155 return function_(CallbackForward(args)...);
154 } 156 }
155 157
156 private: 158 private:
157 R (*function_)(Args...); 159 R (*function_)(Args...);
158 }; 160 };
159 161
160 // Method. 162 // Method.
161 template <typename R, typename T, typename... Args> 163 template <typename R, typename T, typename... Args>
162 class RunnableAdapter<R(T::*)(Args...)> { 164 class RunnableAdapter<R(T::*)(Args...)> {
163 public: 165 public:
164 typedef R (RunType)(T*, Args...); 166 // MSVC 2013 doesn't support Type Alias of function types.
165 typedef true_type IsMethod; 167 // Revisit this after we update it to newer version.
168 typedef R RunType(T*, Args...);
169 using IsMethod = true_type;
166 170
167 explicit RunnableAdapter(R(T::*method)(Args...)) 171 explicit RunnableAdapter(R(T::*method)(Args...))
168 : method_(method) { 172 : method_(method) {
169 } 173 }
170 174
171 R Run(T* object, typename CallbackParamTraits<Args>::ForwardType... args) { 175 R Run(T* object, typename CallbackParamTraits<Args>::ForwardType... args) {
172 return (object->*method_)(CallbackForward(args)...); 176 return (object->*method_)(CallbackForward(args)...);
173 } 177 }
174 178
175 private: 179 private:
176 R (T::*method_)(Args...); 180 R (T::*method_)(Args...);
177 }; 181 };
178 182
179 // Const Method. 183 // Const Method.
180 template <typename R, typename T, typename... Args> 184 template <typename R, typename T, typename... Args>
181 class RunnableAdapter<R(T::*)(Args...) const> { 185 class RunnableAdapter<R(T::*)(Args...) const> {
182 public: 186 public:
183 typedef R (RunType)(const T*, Args...); 187 using RunType = R(const T*, Args...);
184 typedef true_type IsMethod; 188 using IsMethod = true_type;
185 189
186 explicit RunnableAdapter(R(T::*method)(Args...) const) 190 explicit RunnableAdapter(R(T::*method)(Args...) const)
187 : method_(method) { 191 : method_(method) {
188 } 192 }
189 193
190 R Run(const T* object, 194 R Run(const T* object,
191 typename CallbackParamTraits<Args>::ForwardType... args) { 195 typename CallbackParamTraits<Args>::ForwardType... args) {
192 return (object->*method_)(CallbackForward(args)...); 196 return (object->*method_)(CallbackForward(args)...);
193 } 197 }
194 198
195 private: 199 private:
196 R (T::*method_)(Args...) const; 200 R (T::*method_)(Args...) const;
197 }; 201 };
198 202
199 203
200 // ForceVoidReturn<> 204 // ForceVoidReturn<>
201 // 205 //
202 // Set of templates that support forcing the function return type to void. 206 // Set of templates that support forcing the function return type to void.
203 template <typename Sig> 207 template <typename Sig>
204 struct ForceVoidReturn; 208 struct ForceVoidReturn;
205 209
206 template <typename R, typename... Args> 210 template <typename R, typename... Args>
207 struct ForceVoidReturn<R(Args...)> { 211 struct ForceVoidReturn<R(Args...)> {
208 typedef void(RunType)(Args...); 212 // MSVC 2013 doesn't support Type Alias of function types.
213 // Revisit this after we update it to newer version.
214 typedef void RunType(Args...);
209 }; 215 };
210 216
211 217
212 // FunctorTraits<> 218 // FunctorTraits<>
213 // 219 //
214 // See description at top of file. 220 // See description at top of file.
215 template <typename T> 221 template <typename T>
216 struct FunctorTraits { 222 struct FunctorTraits {
217 typedef RunnableAdapter<T> RunnableType; 223 using RunnableType = RunnableAdapter<T>;
218 typedef typename RunnableType::RunType RunType; 224 using RunType = typename RunnableType::RunType;
219 }; 225 };
220 226
221 template <typename T> 227 template <typename T>
222 struct FunctorTraits<IgnoreResultHelper<T>> { 228 struct FunctorTraits<IgnoreResultHelper<T>> {
223 typedef typename FunctorTraits<T>::RunnableType RunnableType; 229 using RunnableType = typename FunctorTraits<T>::RunnableType;
224 typedef typename ForceVoidReturn< 230 using RunType =
225 typename RunnableType::RunType>::RunType RunType; 231 typename ForceVoidReturn<typename RunnableType::RunType>::RunType;
226 }; 232 };
227 233
228 template <typename T> 234 template <typename T>
229 struct FunctorTraits<Callback<T>> { 235 struct FunctorTraits<Callback<T>> {
230 typedef Callback<T> RunnableType; 236 using RunnableType = Callback<T> ;
231 typedef typename Callback<T>::RunType RunType; 237 using RunType = typename Callback<T>::RunType;
232 }; 238 };
233 239
234 240
235 // MakeRunnable<> 241 // MakeRunnable<>
236 // 242 //
237 // Converts a passed in functor to a RunnableType using type inference. 243 // Converts a passed in functor to a RunnableType using type inference.
238 244
239 template <typename T> 245 template <typename T>
240 typename FunctorTraits<T>::RunnableType MakeRunnable(const T& t) { 246 typename FunctorTraits<T>::RunnableType MakeRunnable(const T& t) {
241 return RunnableAdapter<T>(t); 247 return RunnableAdapter<T>(t);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 414
409 static void Destroy(BindStateBase* self) { 415 static void Destroy(BindStateBase* self) {
410 delete static_cast<BindState*>(self); 416 delete static_cast<BindState*>(self);
411 } 417 }
412 }; 418 };
413 419
414 } // namespace internal 420 } // namespace internal
415 } // namespace base 421 } // namespace base
416 422
417 #endif // BASE_BIND_INTERNAL_H_ 423 #endif // BASE_BIND_INTERNAL_H_
OLDNEW
« no previous file with comments | « base/bind_helpers.h ('k') | base/bind_internal_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698