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 <tuple> | 10 #include <tuple> |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 public: | 149 public: |
150 // MSVC 2013 doesn't support Type Alias of function types. | 150 // MSVC 2013 doesn't support Type Alias of function types. |
151 // Revisit this after we update it to newer version. | 151 // Revisit this after we update it to newer version. |
152 typedef R RunType(Args...); | 152 typedef R RunType(Args...); |
153 | 153 |
154 explicit RunnableAdapter(R(*function)(Args...)) | 154 explicit RunnableAdapter(R(*function)(Args...)) |
155 : function_(function) { | 155 : function_(function) { |
156 } | 156 } |
157 | 157 |
158 template <typename... RunArgs> | 158 template <typename... RunArgs> |
159 R Run(RunArgs&&... args) { | 159 R Run(RunArgs&&... args) const { |
160 return function_(std::forward<RunArgs>(args)...); | 160 return function_(std::forward<RunArgs>(args)...); |
161 } | 161 } |
162 | 162 |
163 private: | 163 private: |
164 R (*function_)(Args...); | 164 R (*function_)(Args...); |
165 }; | 165 }; |
166 | 166 |
167 // Method. | 167 // Method. |
168 template <typename R, typename T, typename... Args> | 168 template <typename R, typename T, typename... Args> |
169 class RunnableAdapter<R(T::*)(Args...)> { | 169 class RunnableAdapter<R(T::*)(Args...)> { |
170 public: | 170 public: |
171 // MSVC 2013 doesn't support Type Alias of function types. | 171 // MSVC 2013 doesn't support Type Alias of function types. |
172 // Revisit this after we update it to newer version. | 172 // Revisit this after we update it to newer version. |
173 typedef R RunType(T*, Args...); | 173 typedef R RunType(T*, Args...); |
174 using IsMethod = std::true_type; | 174 using IsMethod = std::true_type; |
175 | 175 |
176 explicit RunnableAdapter(R(T::*method)(Args...)) | 176 explicit RunnableAdapter(R(T::*method)(Args...)) |
177 : method_(method) { | 177 : method_(method) { |
178 } | 178 } |
179 | 179 |
180 template <typename Receiver, typename... RunArgs> | 180 template <typename Receiver, typename... RunArgs> |
181 R Run(Receiver&& receiver_ptr, RunArgs&&... args) { | 181 R Run(Receiver&& receiver_ptr, RunArgs&&... args) const { |
182 // Clang skips CV qualifier check on a method pointer invocation when the | 182 // Clang skips CV qualifier check on a method pointer invocation when the |
183 // receiver is a subclass. Store the receiver into a const reference to | 183 // receiver is a subclass. Store the receiver into a const reference to |
184 // T to ensure the CV check works. | 184 // T to ensure the CV check works. |
185 // https://llvm.org/bugs/show_bug.cgi?id=27037 | 185 // https://llvm.org/bugs/show_bug.cgi?id=27037 |
186 T& receiver = *receiver_ptr; | 186 T& receiver = *receiver_ptr; |
187 return (receiver.*method_)(std::forward<RunArgs>(args)...); | 187 return (receiver.*method_)(std::forward<RunArgs>(args)...); |
188 } | 188 } |
189 | 189 |
190 private: | 190 private: |
191 R (T::*method_)(Args...); | 191 R (T::*method_)(Args...); |
192 }; | 192 }; |
193 | 193 |
194 // Const Method. | 194 // Const Method. |
195 template <typename R, typename T, typename... Args> | 195 template <typename R, typename T, typename... Args> |
196 class RunnableAdapter<R(T::*)(Args...) const> { | 196 class RunnableAdapter<R(T::*)(Args...) const> { |
197 public: | 197 public: |
198 using RunType = R(const T*, Args...); | 198 using RunType = R(const T*, Args...); |
199 using IsMethod = std::true_type; | 199 using IsMethod = std::true_type; |
200 | 200 |
201 explicit RunnableAdapter(R(T::*method)(Args...) const) | 201 explicit RunnableAdapter(R(T::*method)(Args...) const) |
202 : method_(method) { | 202 : method_(method) { |
203 } | 203 } |
204 | 204 |
205 template <typename Receiver, typename... RunArgs> | 205 template <typename Receiver, typename... RunArgs> |
206 R Run(Receiver&& receiver_ptr, RunArgs&&... args) { | 206 R Run(Receiver&& receiver_ptr, RunArgs&&... args) const { |
207 // Clang skips CV qualifier check on a method pointer invocation when the | 207 // Clang skips CV qualifier check on a method pointer invocation when the |
208 // receiver is a subclass. Store the receiver into a unqualified reference | 208 // receiver is a subclass. Store the receiver into a unqualified reference |
209 // to T to ensure the CV check works. | 209 // to T to ensure the CV check works. |
210 // https://llvm.org/bugs/show_bug.cgi?id=27037 | 210 // https://llvm.org/bugs/show_bug.cgi?id=27037 |
211 const T& receiver = *receiver_ptr; | 211 const T& receiver = *receiver_ptr; |
212 return (receiver.*method_)(std::forward<RunArgs>(args)...); | 212 return (receiver.*method_)(std::forward<RunArgs>(args)...); |
213 } | 213 } |
214 | 214 |
215 private: | 215 private: |
216 R (T::*method_)(Args...) const; | 216 R (T::*method_)(Args...) const; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 template <size_t... bound_indices, | 350 template <size_t... bound_indices, |
351 typename StorageType, | 351 typename StorageType, |
352 bool is_weak_call, | 352 bool is_weak_call, |
353 typename R, | 353 typename R, |
354 typename... UnboundArgs> | 354 typename... UnboundArgs> |
355 struct Invoker<IndexSequence<bound_indices...>, | 355 struct Invoker<IndexSequence<bound_indices...>, |
356 StorageType, | 356 StorageType, |
357 is_weak_call, | 357 is_weak_call, |
358 R(UnboundArgs...)> { | 358 R(UnboundArgs...)> { |
359 static R Run(BindStateBase* base, UnboundArgs&&... unbound_args) { | 359 static R Run(BindStateBase* base, UnboundArgs&&... unbound_args) { |
360 StorageType* storage = static_cast<StorageType*>(base); | 360 const StorageType* storage = static_cast<StorageType*>(base); |
361 // Local references to make debugger stepping easier. If in a debugger, | 361 // Local references to make debugger stepping easier. If in a debugger, |
362 // you really want to warp ahead and step through the | 362 // you really want to warp ahead and step through the |
363 // InvokeHelper<>::MakeItSo() call below. | 363 // InvokeHelper<>::MakeItSo() call below. |
364 return InvokeHelper<is_weak_call, R>::MakeItSo( | 364 return InvokeHelper<is_weak_call, R>::MakeItSo( |
365 storage->runnable_, | 365 storage->runnable_, |
366 Unwrap(std::get<bound_indices>(storage->bound_args_))..., | 366 Unwrap(std::get<bound_indices>(storage->bound_args_))..., |
367 std::forward<UnboundArgs>(unbound_args)...); | 367 std::forward<UnboundArgs>(unbound_args)...); |
368 } | 368 } |
369 }; | 369 }; |
370 | 370 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 | 437 |
438 static void Destroy(BindStateBase* self) { | 438 static void Destroy(BindStateBase* self) { |
439 delete static_cast<BindState*>(self); | 439 delete static_cast<BindState*>(self); |
440 } | 440 } |
441 }; | 441 }; |
442 | 442 |
443 } // namespace internal | 443 } // namespace internal |
444 } // namespace base | 444 } // namespace base |
445 | 445 |
446 #endif // BASE_BIND_INTERNAL_H_ | 446 #endif // BASE_BIND_INTERNAL_H_ |
OLD | NEW |