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

Side by Side Diff: base/bind_internal.h

Issue 2042223002: Introduce OnceClosure and BindOnce (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: swap Once & Repeating positions Created 4 years, 3 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.h ('k') | base/bind_unittest.cc » ('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 <tuple> 10 #include <tuple>
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
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( 247 FunctorTraits<T>::Invoke(
248 std::forward<IgnoreResultType>(ignore_result_helper).functor_, 248 std::forward<IgnoreResultType>(ignore_result_helper).functor_,
249 std::forward<RunArgs>(args)...); 249 std::forward<RunArgs>(args)...);
250 } 250 }
251 }; 251 };
252 252
253 // For Callbacks. 253 // For Callbacks.
254 template <typename R, typename... Args, CopyMode copy_mode> 254 template <typename R, typename... Args,
255 struct FunctorTraits<Callback<R(Args...), copy_mode>> { 255 CopyMode copy_mode, RepeatMode repeat_mode>
256 struct FunctorTraits<Callback<R(Args...), copy_mode, repeat_mode>> {
256 using RunType = R(Args...); 257 using RunType = R(Args...);
257 static constexpr bool is_method = false; 258 static constexpr bool is_method = false;
258 static constexpr bool is_nullable = true; 259 static constexpr bool is_nullable = true;
259 260
260 template <typename CallbackType, typename... RunArgs> 261 template <typename CallbackType, typename... RunArgs>
261 static R Invoke(CallbackType&& callback, RunArgs&&... args) { 262 static R Invoke(CallbackType&& callback, RunArgs&&... args) {
262 DCHECK(!callback.is_null()); 263 DCHECK(!callback.is_null());
263 return std::forward<CallbackType>(callback).Run( 264 return std::forward<CallbackType>(callback).Run(
264 std::forward<RunArgs>(args)...); 265 std::forward<RunArgs>(args)...);
265 } 266 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 }; 309 };
309 310
310 // Invoker<> 311 // Invoker<>
311 // 312 //
312 // See description at the top of the file. 313 // See description at the top of the file.
313 template <typename StorageType, typename UnboundRunType> 314 template <typename StorageType, typename UnboundRunType>
314 struct Invoker; 315 struct Invoker;
315 316
316 template <typename StorageType, typename R, typename... UnboundArgs> 317 template <typename StorageType, typename R, typename... UnboundArgs>
317 struct Invoker<StorageType, R(UnboundArgs...)> { 318 struct Invoker<StorageType, R(UnboundArgs...)> {
319 static R RunOnce(BindStateBase* base, UnboundArgs&&... unbound_args) {
320 // Local references to make debugger stepping easier. If in a debugger,
321 // you really want to warp ahead and step through the
322 // InvokeHelper<>::MakeItSo() call below.
323 StorageType* storage = static_cast<StorageType*>(base);
324 static constexpr size_t num_bound_args =
325 std::tuple_size<decltype(storage->bound_args_)>::value;
326 return RunImpl(std::move(storage->functor_),
327 std::move(storage->bound_args_),
328 MakeIndexSequence<num_bound_args>(),
329 std::forward<UnboundArgs>(unbound_args)...);
330 }
331
318 static R Run(BindStateBase* base, UnboundArgs&&... unbound_args) { 332 static R Run(BindStateBase* base, UnboundArgs&&... unbound_args) {
319 // Local references to make debugger stepping easier. If in a debugger, 333 // Local references to make debugger stepping easier. If in a debugger,
320 // you really want to warp ahead and step through the 334 // you really want to warp ahead and step through the
321 // InvokeHelper<>::MakeItSo() call below. 335 // InvokeHelper<>::MakeItSo() call below.
322 const StorageType* storage = static_cast<StorageType*>(base); 336 const StorageType* storage = static_cast<StorageType*>(base);
323 static constexpr size_t num_bound_args = 337 static constexpr size_t num_bound_args =
324 std::tuple_size<decltype(storage->bound_args_)>::value; 338 std::tuple_size<decltype(storage->bound_args_)>::value;
325 return RunImpl(storage->functor_, 339 return RunImpl(storage->functor_,
326 storage->bound_args_, 340 storage->bound_args_,
327 MakeIndexSequence<num_bound_args>(), 341 MakeIndexSequence<num_bound_args>(),
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 494
481 // Returns a RunType of bound functor. 495 // Returns a RunType of bound functor.
482 // E.g. MakeUnboundRunType<R(A, B, C), A, B> is evaluated to R(C). 496 // E.g. MakeUnboundRunType<R(A, B, C), A, B> is evaluated to R(C).
483 template <typename Functor, typename... BoundArgs> 497 template <typename Functor, typename... BoundArgs>
484 using MakeUnboundRunType = 498 using MakeUnboundRunType =
485 typename internal::MakeUnboundRunTypeImpl<Functor, BoundArgs...>::Type; 499 typename internal::MakeUnboundRunTypeImpl<Functor, BoundArgs...>::Type;
486 500
487 } // namespace base 501 } // namespace base
488 502
489 #endif // BASE_BIND_INTERNAL_H_ 503 #endif // BASE_BIND_INTERNAL_H_
OLDNEW
« no previous file with comments | « base/bind.h ('k') | base/bind_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698