| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 237 |
| 238 // For IgnoreResults. | 238 // For IgnoreResults. |
| 239 template <typename T> | 239 template <typename T> |
| 240 struct FunctorTraits<IgnoreResultHelper<T>> : FunctorTraits<T> { | 240 struct FunctorTraits<IgnoreResultHelper<T>> : FunctorTraits<T> { |
| 241 using RunType = | 241 using RunType = |
| 242 typename ForceVoidReturn<typename FunctorTraits<T>::RunType>::RunType; | 242 typename ForceVoidReturn<typename FunctorTraits<T>::RunType>::RunType; |
| 243 | 243 |
| 244 template <typename IgnoreResultType, typename... RunArgs> | 244 template <typename IgnoreResultType, typename... RunArgs> |
| 245 static void Invoke(IgnoreResultType&& ignore_result_helper, | 245 static void Invoke(IgnoreResultType&& ignore_result_helper, |
| 246 RunArgs&&... args) { | 246 RunArgs&&... args) { |
| 247 FunctorTraits<T>::Invoke(ignore_result_helper.functor_, | 247 FunctorTraits<T>::Invoke( |
| 248 std::forward<RunArgs>(args)...); | 248 std::forward<IgnoreResultType>(ignore_result_helper).functor_, |
| 249 std::forward<RunArgs>(args)...); |
| 249 } | 250 } |
| 250 }; | 251 }; |
| 251 | 252 |
| 252 // For Callbacks. | 253 // For Callbacks. |
| 253 template <typename R, typename... Args, CopyMode copy_mode> | 254 template <typename R, typename... Args, |
| 254 struct FunctorTraits<Callback<R(Args...), copy_mode>> { | 255 CopyMode copy_mode, RepeatMode repeat_mode> |
| 256 struct FunctorTraits<Callback<R(Args...), copy_mode, repeat_mode>> { |
| 255 using RunType = R(Args...); | 257 using RunType = R(Args...); |
| 256 static constexpr bool is_method = false; | 258 static constexpr bool is_method = false; |
| 257 static constexpr bool is_nullable = true; | 259 static constexpr bool is_nullable = true; |
| 258 | 260 |
| 259 template <typename CallbackType, typename... RunArgs> | 261 template <typename CallbackType, typename... RunArgs> |
| 260 static R Invoke(CallbackType&& callback, RunArgs&&... args) { | 262 static R Invoke(CallbackType&& callback, RunArgs&&... args) { |
| 261 DCHECK(!callback.is_null()); | 263 DCHECK(!callback.is_null()); |
| 262 return std::forward<CallbackType>(callback).Run( | 264 return std::forward<CallbackType>(callback).Run( |
| 263 std::forward<RunArgs>(args)...); | 265 std::forward<RunArgs>(args)...); |
| 264 } | 266 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 // InvokeHelper<>::MakeItSo() call below. | 322 // InvokeHelper<>::MakeItSo() call below. |
| 321 const StorageType* storage = static_cast<StorageType*>(base); | 323 const StorageType* storage = static_cast<StorageType*>(base); |
| 322 static constexpr size_t num_bound_args = | 324 static constexpr size_t num_bound_args = |
| 323 std::tuple_size<decltype(storage->bound_args_)>::value; | 325 std::tuple_size<decltype(storage->bound_args_)>::value; |
| 324 return RunImpl(storage->functor_, | 326 return RunImpl(storage->functor_, |
| 325 storage->bound_args_, | 327 storage->bound_args_, |
| 326 MakeIndexSequence<num_bound_args>(), | 328 MakeIndexSequence<num_bound_args>(), |
| 327 std::forward<UnboundArgs>(unbound_args)...); | 329 std::forward<UnboundArgs>(unbound_args)...); |
| 328 } | 330 } |
| 329 | 331 |
| 332 static R RunOneShot(BindStateBase* base, UnboundArgs&&... unbound_args) { |
| 333 // Local references to make debugger stepping easier. If in a debugger, |
| 334 // you really want to warp ahead and step through the |
| 335 // InvokeHelper<>::MakeItSo() call below. |
| 336 StorageType* storage = static_cast<StorageType*>(base); |
| 337 static constexpr size_t num_bound_args = |
| 338 std::tuple_size<decltype(storage->bound_args_)>::value; |
| 339 return RunImpl(std::move(storage->functor_), |
| 340 std::move(storage->bound_args_), |
| 341 MakeIndexSequence<num_bound_args>(), |
| 342 std::forward<UnboundArgs>(unbound_args)...); |
| 343 } |
| 344 |
| 330 private: | 345 private: |
| 331 template <typename Functor, typename BoundArgsTuple, size_t... indices> | 346 template <typename Functor, typename BoundArgsTuple, size_t... indices> |
| 332 static inline R RunImpl(Functor&& functor, | 347 static inline R RunImpl(Functor&& functor, |
| 333 BoundArgsTuple&& bound, | 348 BoundArgsTuple&& bound, |
| 334 IndexSequence<indices...>, | 349 IndexSequence<indices...>, |
| 335 UnboundArgs&&... unbound_args) { | 350 UnboundArgs&&... unbound_args) { |
| 336 static constexpr bool is_method = | 351 static constexpr bool is_method = |
| 337 FunctorTraits<typename std::decay<Functor>::type>::is_method; | 352 FunctorTraits<typename std::decay<Functor>::type>::is_method; |
| 338 | 353 |
| 339 using DecayedArgsTuple = typename std::decay<BoundArgsTuple>::type; | 354 using DecayedArgsTuple = typename std::decay<BoundArgsTuple>::type; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 459 |
| 445 // Returns a RunType of bound functor. | 460 // Returns a RunType of bound functor. |
| 446 // E.g. MakeUnboundRunType<R(A, B, C), A, B> is evaluated to R(C). | 461 // E.g. MakeUnboundRunType<R(A, B, C), A, B> is evaluated to R(C). |
| 447 template <typename Functor, typename... BoundArgs> | 462 template <typename Functor, typename... BoundArgs> |
| 448 using MakeUnboundRunType = | 463 using MakeUnboundRunType = |
| 449 typename internal::MakeUnboundRunTypeImpl<Functor, BoundArgs...>::Type; | 464 typename internal::MakeUnboundRunTypeImpl<Functor, BoundArgs...>::Type; |
| 450 | 465 |
| 451 } // namespace base | 466 } // namespace base |
| 452 | 467 |
| 453 #endif // BASE_BIND_INTERNAL_H_ | 468 #endif // BASE_BIND_INTERNAL_H_ |
| OLD | NEW |