diff options
author | tzik <tzik@chromium.org> | 2015-02-05 11:11:26 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-05 19:12:47 +0000 |
commit | 8ce65709225bac5922e6b2b80a912cf9796949b1 (patch) | |
tree | 6b7339e48649d2e469079565a8e7d3e1d0ca06dd | |
parent | d5626f6497c92188cc5d88b6778f7bae0b33c1b3 (diff) | |
download | chromium_src-8ce65709225bac5922e6b2b80a912cf9796949b1.zip chromium_src-8ce65709225bac5922e6b2b80a912cf9796949b1.tar.gz chromium_src-8ce65709225bac5922e6b2b80a912cf9796949b1.tar.bz2 |
Bind: Use Variadic Templates in bind_internal.h
* Introduce TypeList as helpers.
* Drop bind_internal.h.pump and replace generated codes with Variadic Templates version.
BUG=433164
Review URL: https://codereview.chromium.org/743853002
Cr-Commit-Position: refs/heads/master@{#314847}
-rw-r--r-- | base/bind.h | 14 | ||||
-rw-r--r-- | base/bind_helpers.h | 139 | ||||
-rw-r--r-- | base/bind_internal.h | 1822 | ||||
-rw-r--r-- | base/bind_internal.h.pump | 516 | ||||
-rw-r--r-- | base/bind_unittest.nc | 2 |
5 files changed, 178 insertions, 2315 deletions
diff --git a/base/bind.h b/base/bind.h index 7874656..51be10d 100644 --- a/base/bind.h +++ b/base/bind.h @@ -52,13 +52,14 @@ base::Callback< typename internal::BindState< typename internal::FunctorTraits<Functor>::RunnableType, typename internal::FunctorTraits<Functor>::RunType, - void()>::UnboundRunType> + internal::TypeList<>>::UnboundRunType> Bind(Functor functor) { // Typedefs for how to store and run the functor. typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; typedef typename internal::FunctorTraits<Functor>::RunType RunType; - typedef internal::BindState<RunnableType, RunType, void()> BindState; + typedef internal::BindState<RunnableType, RunType, + internal::TypeList<>> BindState; return Callback<typename BindState::UnboundRunType>( new BindState(internal::MakeRunnable(functor))); @@ -69,7 +70,8 @@ base::Callback< typename internal::BindState< typename internal::FunctorTraits<Functor>::RunnableType, typename internal::FunctorTraits<Functor>::RunType, - void(typename internal::CallbackParamTraits<Args>::StorageType...)> + internal::TypeList< + typename internal::CallbackParamTraits<Args>::StorageType...>> ::UnboundRunType> Bind(Functor functor, const Args&... args) { // Typedefs for how to store and run the functor. @@ -101,8 +103,10 @@ Bind(Functor functor, const Args&... args) { !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value, "a_parameter_is_refcounted_type_and_needs_scoped_refptr"); - typedef internal::BindState<RunnableType, RunType, - void(typename internal::CallbackParamTraits<Args>::StorageType...)> + typedef internal::BindState< + RunnableType, RunType, + internal::TypeList< + typename internal::CallbackParamTraits<Args>::StorageType...>> BindState; return Callback<typename BindState::UnboundRunType>( diff --git a/base/bind_helpers.h b/base/bind_helpers.h index f3efc31..f8e89bd 100644 --- a/base/bind_helpers.h +++ b/base/bind_helpers.h @@ -435,45 +435,46 @@ struct UnwrapTraits<PassedWrapper<T> > { // Utility for handling different refcounting semantics in the Bind() // function. -template <bool is_method, typename T> -struct MaybeRefcount; +template <bool is_method, typename... T> +struct MaybeScopedRefPtr; -template <typename T> -struct MaybeRefcount<false, T> { - static void AddRef(const T&) {} - static void Release(const T&) {} +template <bool is_method> +struct MaybeScopedRefPtr<is_method> { + MaybeScopedRefPtr() {} }; -template <typename T, size_t n> -struct MaybeRefcount<false, T[n]> { - static void AddRef(const T*) {} - static void Release(const T*) {} +template <typename T, typename... Rest> +struct MaybeScopedRefPtr<false, T, Rest...> { + MaybeScopedRefPtr(const T&, const Rest&...) {} }; -template <typename T> -struct MaybeRefcount<true, T> { - static void AddRef(const T&) {} - static void Release(const T&) {} +template <typename T, size_t n, typename... Rest> +struct MaybeScopedRefPtr<false, T[n], Rest...> { + MaybeScopedRefPtr(const T*, const Rest&...) {} }; -template <typename T> -struct MaybeRefcount<true, T*> { - static void AddRef(T* o) { o->AddRef(); } - static void Release(T* o) { o->Release(); } +template <typename T, typename... Rest> +struct MaybeScopedRefPtr<true, T, Rest...> { + MaybeScopedRefPtr(const T& o, const Rest&...) {} +}; + +template <typename T, typename... Rest> +struct MaybeScopedRefPtr<true, T*, Rest...> { + MaybeScopedRefPtr(T* o, const Rest&...) : ref_(o) {} + scoped_refptr<T> ref_; }; // No need to additionally AddRef() and Release() since we are storing a // scoped_refptr<> inside the storage object already. -template <typename T> -struct MaybeRefcount<true, scoped_refptr<T> > { - static void AddRef(const scoped_refptr<T>& o) {} - static void Release(const scoped_refptr<T>& o) {} +template <typename T, typename... Rest> +struct MaybeScopedRefPtr<true, scoped_refptr<T>, Rest...> { + MaybeScopedRefPtr(const scoped_refptr<T>&, const Rest&...) {} }; -template <typename T> -struct MaybeRefcount<true, const T*> { - static void AddRef(const T* o) { o->AddRef(); } - static void Release(const T* o) { o->Release(); } +template <typename T, typename... Rest> +struct MaybeScopedRefPtr<true, const T*, Rest...> { + MaybeScopedRefPtr(const T* o, const Rest&...) : ref_(o) {} + scoped_refptr<const T> ref_; }; // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a @@ -481,15 +482,89 @@ struct MaybeRefcount<true, const T*> { // InvokeHelper that will no-op itself in the event the WeakPtr<> for // the target object is invalidated. // -// P1 should be the type of the object that will be received of the method. -template <bool IsMethod, typename P1> +// The first argument should be the type of the object that will be received by +// the method. +template <bool IsMethod, typename... Args> struct IsWeakMethod : public false_type {}; -template <typename T> -struct IsWeakMethod<true, WeakPtr<T> > : public true_type {}; +template <typename T, typename... Args> +struct IsWeakMethod<true, WeakPtr<T>, Args...> : public true_type {}; -template <typename T> -struct IsWeakMethod<true, ConstRefWrapper<WeakPtr<T> > > : public true_type {}; +template <typename T, typename... Args> +struct IsWeakMethod<true, ConstRefWrapper<WeakPtr<T>>, Args...> + : public true_type {}; + + +// Packs a list of types to hold them in a single type. +template <typename... Types> +struct TypeList {}; + +// Used for DropTypeListItem implementation. +template <size_t n, typename List> +struct DropTypeListItemImpl; + +// Do not use enable_if and SFINAE here to avoid MSVC2013 compile failure. +template <size_t n, typename T, typename... List> +struct DropTypeListItemImpl<n, TypeList<T, List...>> + : DropTypeListItemImpl<n - 1, TypeList<List...>> {}; + +template <typename T, typename... List> +struct DropTypeListItemImpl<0, TypeList<T, List...>> { + typedef TypeList<T, List...> Type; +}; + +template <> +struct DropTypeListItemImpl<0, TypeList<>> { + typedef TypeList<> Type; +}; + +// A type-level function that drops |n| list item from given TypeList. +template <size_t n, typename List> +using DropTypeListItem = typename DropTypeListItemImpl<n, List>::Type; + +// Used for ConcatTypeLists implementation. +template <typename List1, typename List2> +struct ConcatTypeListsImpl; + +template <typename... Types1, typename... Types2> +struct ConcatTypeListsImpl<TypeList<Types1...>, TypeList<Types2...>> { + typedef TypeList<Types1..., Types2...> Type; +}; + +// A type-level function that concats two TypeLists. +template <typename List1, typename List2> +using ConcatTypeLists = typename ConcatTypeListsImpl<List1, List2>::Type; + +template <size_t n, typename List> +struct NthTypeImpl; + +template <size_t n, typename T, typename... Types> +struct NthTypeImpl<n, TypeList<T, Types...>> + : NthTypeImpl<n - 1, TypeList<Types...>> { +}; + +template <typename T, typename... Types> +struct NthTypeImpl<0, TypeList<T, Types...>> { + typedef T Type; +}; + +// A type-level function that extracts |n|th type from a TypeList. +template <size_t n, typename List> +using NthType = typename NthTypeImpl<n, List>::Type; + +// Used for MakeFunctionType implementation. +template <typename R, typename ArgList> +struct MakeFunctionTypeImpl; + +template <typename R, typename... Args> +struct MakeFunctionTypeImpl<R, TypeList<Args...>> { + typedef R(Type)(Args...); +}; + +// A type-level function that constructs a function type that has |R| as its +// return type and has TypeLists items as its arguments. +template <typename R, typename ArgList> +using MakeFunctionType = typename MakeFunctionTypeImpl<R, ArgList>::Type; } // namespace internal diff --git a/base/bind_internal.h b/base/bind_internal.h index b568c16..5fc1459 100644 --- a/base/bind_internal.h +++ b/base/bind_internal.h @@ -1,8 +1,3 @@ -// This file was GENERATED by command: -// pump.py bind_internal.h.pump -// DO NOT EDIT BY HAND!!! - - // Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -15,6 +10,7 @@ #include "base/memory/raw_scoped_refptr_mismatch_checker.h" #include "base/memory/weak_ptr.h" #include "base/template_util.h" +#include "base/tuple.h" #include "build/build_config.h" #if defined(OS_WIN) @@ -51,10 +47,6 @@ namespace internal { // Types: // RunnableAdapter<> -- Wraps the various "function" pointer types into an // object that adheres to the Runnable interface. -// FunctionTraits<> -- Type traits that unwrap a function signature into a -// a set of easier to use typedefs. Used mainly for -// compile time asserts. -// There are |ARITY| FunctionTraits types. // ForceVoidReturn<> -- Helper class for translating function signatures to // equivalent forms with a "void" return type. // FunctorTraits<> -- Type traits used determine the correct RunType and @@ -64,12 +56,11 @@ namespace internal { // type class that represents the underlying Functor. // There are |O(1)| MakeRunnable types. // InvokeHelper<> -- Take a Runnable + arguments and actully invokes it. -// Handle the differing syntaxes needed for WeakPtr<> support, -// and for ignoring return values. This is separate from -// Invoker to avoid creating multiple version of Invoker<> -// which grows at O(n^2) with the arity. +// Handle the differing syntaxes needed for WeakPtr<> +// support, and for ignoring return values. This is separate +// from Invoker to avoid creating multiple version of +// Invoker<>. // Invoker<> -- Unwraps the curried parameters and executes the Runnable. -// There are |(ARITY^2 + ARITY)/2| Invoketypes. // BindState<> -- Stores the curried parameters, and is the main entry point // into the Bind() system, doing most of the type resolution. // There are ARITY BindState types. @@ -209,84 +200,6 @@ class RunnableAdapter<R(T::*)(Args...) const> { R (T::*method_)(Args...) const; }; -// TODO(tzik): Remove FunctionTraits after we finish removing bind.pump. -// FunctionTraits<> -// -// Breaks a function signature apart into typedefs for easier introspection. -template <typename Sig> -struct FunctionTraits; - -template <typename R> -struct FunctionTraits<R()> { - typedef R ReturnType; -}; - -template <typename R, typename A1> -struct FunctionTraits<R(A1)> { - typedef R ReturnType; - typedef A1 A1Type; -}; - -template <typename R, typename A1, typename A2> -struct FunctionTraits<R(A1, A2)> { - typedef R ReturnType; - typedef A1 A1Type; - typedef A2 A2Type; -}; - -template <typename R, typename A1, typename A2, typename A3> -struct FunctionTraits<R(A1, A2, A3)> { - typedef R ReturnType; - typedef A1 A1Type; - typedef A2 A2Type; - typedef A3 A3Type; -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4> -struct FunctionTraits<R(A1, A2, A3, A4)> { - typedef R ReturnType; - typedef A1 A1Type; - typedef A2 A2Type; - typedef A3 A3Type; - typedef A4 A4Type; -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5> -struct FunctionTraits<R(A1, A2, A3, A4, A5)> { - typedef R ReturnType; - typedef A1 A1Type; - typedef A2 A2Type; - typedef A3 A3Type; - typedef A4 A4Type; - typedef A5 A5Type; -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6> -struct FunctionTraits<R(A1, A2, A3, A4, A5, A6)> { - typedef R ReturnType; - typedef A1 A1Type; - typedef A2 A2Type; - typedef A3 A3Type; - typedef A4 A4Type; - typedef A5 A5Type; - typedef A6 A6Type; -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6, typename A7> -struct FunctionTraits<R(A1, A2, A3, A4, A5, A6, A7)> { - typedef R ReturnType; - typedef A1 A1Type; - typedef A2 A2Type; - typedef A3 A3Type; - typedef A4 A4Type; - typedef A5 A5Type; - typedef A6 A6Type; - typedef A7 A7Type; -}; - // ForceVoidReturn<> // @@ -310,14 +223,14 @@ struct FunctorTraits { }; template <typename T> -struct FunctorTraits<IgnoreResultHelper<T> > { +struct FunctorTraits<IgnoreResultHelper<T>> { typedef typename FunctorTraits<T>::RunnableType RunnableType; typedef typename ForceVoidReturn< typename RunnableType::RunType>::RunType RunType; }; template <typename T> -struct FunctorTraits<Callback<T> > { +struct FunctorTraits<Callback<T>> { typedef Callback<T> RunnableType; typedef typename Callback<T>::RunType RunType; }; @@ -339,7 +252,7 @@ MakeRunnable(const IgnoreResultHelper<T>& t) { } template <typename T> -const typename FunctorTraits<Callback<T> >::RunnableType& +const typename FunctorTraits<Callback<T>>::RunnableType& MakeRunnable(const Callback<T>& t) { DCHECK(!t.is_null()); return t; @@ -368,22 +281,21 @@ template <bool IsWeakCall, typename ReturnType, typename Runnable, struct InvokeHelper; template <typename ReturnType, typename Runnable, typename... Args> -struct InvokeHelper<false, ReturnType, Runnable, - void(Args...)> { +struct InvokeHelper<false, ReturnType, Runnable, TypeList<Args...>> { static ReturnType MakeItSo(Runnable runnable, Args... args) { return runnable.Run(CallbackForward(args)...); } }; template <typename Runnable, typename... Args> -struct InvokeHelper<false, void, Runnable, void(Args...)> { +struct InvokeHelper<false, void, Runnable, TypeList<Args...>> { static void MakeItSo(Runnable runnable, Args... args) { runnable.Run(CallbackForward(args)...); } }; template <typename Runnable, typename BoundWeakPtr, typename... Args> -struct InvokeHelper<true, void, Runnable, void(BoundWeakPtr, Args...)> { +struct InvokeHelper<true, void, Runnable, TypeList<BoundWeakPtr, Args...>> { static void MakeItSo(Runnable runnable, BoundWeakPtr weak_ptr, Args... args) { if (!weak_ptr.get()) { return; @@ -408,1419 +320,30 @@ struct InvokeHelper<true, ReturnType, Runnable, ArgsType> { // Invoker<> // // See description at the top of the file. -template <int NumBound, typename Storage, typename RunType> +template <typename BoundIndices, + typename StorageType, typename Unwrappers, + typename InvokeHelperType, typename UnboundForwardRunType> struct Invoker; -// Arity 0 -> 0. -template <typename StorageType, typename R> -struct Invoker<0, StorageType, R()> { - typedef R(RunType)(BindStateBase*); - - typedef R(UnboundRunType)(); - - static R Run(BindStateBase* base) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void()> - ::MakeItSo(storage->runnable_); - } -}; - -// Arity 1 -> 1. -template <typename StorageType, typename R,typename X1> -struct Invoker<0, StorageType, R(X1)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X1>::ForwardType); - - typedef R(UnboundRunType)(X1); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X1>::ForwardType x1) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename CallbackParamTraits<X1>::ForwardType x1)> - ::MakeItSo(storage->runnable_, CallbackForward(x1)); - } -}; - -// Arity 1 -> 0. -template <typename StorageType, typename R,typename X1> -struct Invoker<1, StorageType, R(X1)> { - typedef R(RunType)(BindStateBase*); - - typedef R(UnboundRunType)(); - - static R Run(BindStateBase* base) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType)> - ::MakeItSo(storage->runnable_, CallbackForward(x1)); - } -}; - -// Arity 2 -> 2. -template <typename StorageType, typename R,typename X1, typename X2> -struct Invoker<0, StorageType, R(X1, X2)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X1>::ForwardType, - typename CallbackParamTraits<X2>::ForwardType); - - typedef R(UnboundRunType)(X1, X2); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X1>::ForwardType x1, - typename CallbackParamTraits<X2>::ForwardType x2) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename CallbackParamTraits<X1>::ForwardType x1, - typename CallbackParamTraits<X2>::ForwardType x2)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2)); - } -}; - -// Arity 2 -> 1. -template <typename StorageType, typename R,typename X1, typename X2> -struct Invoker<1, StorageType, R(X1, X2)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X2>::ForwardType); - - typedef R(UnboundRunType)(X2); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X2>::ForwardType x2) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename CallbackParamTraits<X2>::ForwardType x2)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2)); - } -}; - -// Arity 2 -> 0. -template <typename StorageType, typename R,typename X1, typename X2> -struct Invoker<2, StorageType, R(X1, X2)> { - typedef R(RunType)(BindStateBase*); - - typedef R(UnboundRunType)(); - - static R Run(BindStateBase* base) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2)); - } -}; - -// Arity 3 -> 3. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3> -struct Invoker<0, StorageType, R(X1, X2, X3)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X1>::ForwardType, - typename CallbackParamTraits<X2>::ForwardType, - typename CallbackParamTraits<X3>::ForwardType); - - typedef R(UnboundRunType)(X1, X2, X3); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X1>::ForwardType x1, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename CallbackParamTraits<X1>::ForwardType x1, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3)); - } -}; - -// Arity 3 -> 2. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3> -struct Invoker<1, StorageType, R(X1, X2, X3)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X2>::ForwardType, - typename CallbackParamTraits<X3>::ForwardType); - - typedef R(UnboundRunType)(X2, X3); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3)); - } -}; - -// Arity 3 -> 1. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3> -struct Invoker<2, StorageType, R(X1, X2, X3)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X3>::ForwardType); - - typedef R(UnboundRunType)(X3); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X3>::ForwardType x3) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename CallbackParamTraits<X3>::ForwardType x3)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3)); - } -}; - -// Arity 3 -> 0. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3> -struct Invoker<3, StorageType, R(X1, X2, X3)> { - typedef R(RunType)(BindStateBase*); - - typedef R(UnboundRunType)(); - - static R Run(BindStateBase* base) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3)); - } -}; - -// Arity 4 -> 4. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4> -struct Invoker<0, StorageType, R(X1, X2, X3, X4)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X1>::ForwardType, - typename CallbackParamTraits<X2>::ForwardType, - typename CallbackParamTraits<X3>::ForwardType, - typename CallbackParamTraits<X4>::ForwardType); - - typedef R(UnboundRunType)(X1, X2, X3, X4); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X1>::ForwardType x1, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename CallbackParamTraits<X1>::ForwardType x1, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4)); - } -}; - -// Arity 4 -> 3. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4> -struct Invoker<1, StorageType, R(X1, X2, X3, X4)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X2>::ForwardType, - typename CallbackParamTraits<X3>::ForwardType, - typename CallbackParamTraits<X4>::ForwardType); - - typedef R(UnboundRunType)(X2, X3, X4); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4)); - } -}; - -// Arity 4 -> 2. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4> -struct Invoker<2, StorageType, R(X1, X2, X3, X4)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X3>::ForwardType, - typename CallbackParamTraits<X4>::ForwardType); - - typedef R(UnboundRunType)(X3, X4); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4)); - } -}; - -// Arity 4 -> 1. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4> -struct Invoker<3, StorageType, R(X1, X2, X3, X4)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X4>::ForwardType); - - typedef R(UnboundRunType)(X4); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X4>::ForwardType x4) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType, - typename CallbackParamTraits<X4>::ForwardType x4)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4)); - } -}; - -// Arity 4 -> 0. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4> -struct Invoker<4, StorageType, R(X1, X2, X3, X4)> { - typedef R(RunType)(BindStateBase*); - - typedef R(UnboundRunType)(); - - static R Run(BindStateBase* base) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - typename Bound4UnwrapTraits::ForwardType x4 = - Bound4UnwrapTraits::Unwrap(storage->p4_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType, - typename Bound4UnwrapTraits::ForwardType)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4)); - } -}; - -// Arity 5 -> 5. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5> -struct Invoker<0, StorageType, R(X1, X2, X3, X4, X5)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X1>::ForwardType, - typename CallbackParamTraits<X2>::ForwardType, - typename CallbackParamTraits<X3>::ForwardType, - typename CallbackParamTraits<X4>::ForwardType, - typename CallbackParamTraits<X5>::ForwardType); - - typedef R(UnboundRunType)(X1, X2, X3, X4, X5); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X1>::ForwardType x1, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename CallbackParamTraits<X1>::ForwardType x1, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5)); - } -}; - -// Arity 5 -> 4. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5> -struct Invoker<1, StorageType, R(X1, X2, X3, X4, X5)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X2>::ForwardType, - typename CallbackParamTraits<X3>::ForwardType, - typename CallbackParamTraits<X4>::ForwardType, - typename CallbackParamTraits<X5>::ForwardType); - - typedef R(UnboundRunType)(X2, X3, X4, X5); - +template <size_t... bound_indices, + typename StorageType, + typename... Unwrappers, + typename InvokeHelperType, + typename R, + typename... UnboundForwardArgs> +struct Invoker<IndexSequence<bound_indices...>, + StorageType, TypeList<Unwrappers...>, + InvokeHelperType, R(UnboundForwardArgs...)> { static R Run(BindStateBase* base, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5) { + UnboundForwardArgs... unbound_args) { StorageType* storage = static_cast<StorageType*>(base); - // Local references to make debugger stepping easier. If in a debugger, // you really want to warp ahead and step through the // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5)); - } -}; - -// Arity 5 -> 3. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5> -struct Invoker<2, StorageType, R(X1, X2, X3, X4, X5)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X3>::ForwardType, - typename CallbackParamTraits<X4>::ForwardType, - typename CallbackParamTraits<X5>::ForwardType); - - typedef R(UnboundRunType)(X3, X4, X5); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5)); - } -}; - -// Arity 5 -> 2. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5> -struct Invoker<3, StorageType, R(X1, X2, X3, X4, X5)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X4>::ForwardType, - typename CallbackParamTraits<X5>::ForwardType); - - typedef R(UnboundRunType)(X4, X5); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5)); - } -}; - -// Arity 5 -> 1. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5> -struct Invoker<4, StorageType, R(X1, X2, X3, X4, X5)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X5>::ForwardType); - - typedef R(UnboundRunType)(X5); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X5>::ForwardType x5) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - typename Bound4UnwrapTraits::ForwardType x4 = - Bound4UnwrapTraits::Unwrap(storage->p4_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType, - typename Bound4UnwrapTraits::ForwardType, - typename CallbackParamTraits<X5>::ForwardType x5)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5)); - } -}; - -// Arity 5 -> 0. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5> -struct Invoker<5, StorageType, R(X1, X2, X3, X4, X5)> { - typedef R(RunType)(BindStateBase*); - - typedef R(UnboundRunType)(); - - static R Run(BindStateBase* base) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits; - typedef typename StorageType::Bound5UnwrapTraits Bound5UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - typename Bound4UnwrapTraits::ForwardType x4 = - Bound4UnwrapTraits::Unwrap(storage->p4_); - typename Bound5UnwrapTraits::ForwardType x5 = - Bound5UnwrapTraits::Unwrap(storage->p5_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType, - typename Bound4UnwrapTraits::ForwardType, - typename Bound5UnwrapTraits::ForwardType)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5)); - } -}; - -// Arity 6 -> 6. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6> -struct Invoker<0, StorageType, R(X1, X2, X3, X4, X5, X6)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X1>::ForwardType, - typename CallbackParamTraits<X2>::ForwardType, - typename CallbackParamTraits<X3>::ForwardType, - typename CallbackParamTraits<X4>::ForwardType, - typename CallbackParamTraits<X5>::ForwardType, - typename CallbackParamTraits<X6>::ForwardType); - - typedef R(UnboundRunType)(X1, X2, X3, X4, X5, X6); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X1>::ForwardType x1, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename CallbackParamTraits<X1>::ForwardType x1, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6)); - } -}; - -// Arity 6 -> 5. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6> -struct Invoker<1, StorageType, R(X1, X2, X3, X4, X5, X6)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X2>::ForwardType, - typename CallbackParamTraits<X3>::ForwardType, - typename CallbackParamTraits<X4>::ForwardType, - typename CallbackParamTraits<X5>::ForwardType, - typename CallbackParamTraits<X6>::ForwardType); - - typedef R(UnboundRunType)(X2, X3, X4, X5, X6); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6)); - } -}; - -// Arity 6 -> 4. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6> -struct Invoker<2, StorageType, R(X1, X2, X3, X4, X5, X6)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X3>::ForwardType, - typename CallbackParamTraits<X4>::ForwardType, - typename CallbackParamTraits<X5>::ForwardType, - typename CallbackParamTraits<X6>::ForwardType); - - typedef R(UnboundRunType)(X3, X4, X5, X6); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6)); - } -}; - -// Arity 6 -> 3. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6> -struct Invoker<3, StorageType, R(X1, X2, X3, X4, X5, X6)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X4>::ForwardType, - typename CallbackParamTraits<X5>::ForwardType, - typename CallbackParamTraits<X6>::ForwardType); - - typedef R(UnboundRunType)(X4, X5, X6); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6)); - } -}; - -// Arity 6 -> 2. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6> -struct Invoker<4, StorageType, R(X1, X2, X3, X4, X5, X6)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X5>::ForwardType, - typename CallbackParamTraits<X6>::ForwardType); - - typedef R(UnboundRunType)(X5, X6); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - typename Bound4UnwrapTraits::ForwardType x4 = - Bound4UnwrapTraits::Unwrap(storage->p4_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType, - typename Bound4UnwrapTraits::ForwardType, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6)); - } -}; - -// Arity 6 -> 1. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6> -struct Invoker<5, StorageType, R(X1, X2, X3, X4, X5, X6)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X6>::ForwardType); - - typedef R(UnboundRunType)(X6); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X6>::ForwardType x6) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits; - typedef typename StorageType::Bound5UnwrapTraits Bound5UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - typename Bound4UnwrapTraits::ForwardType x4 = - Bound4UnwrapTraits::Unwrap(storage->p4_); - typename Bound5UnwrapTraits::ForwardType x5 = - Bound5UnwrapTraits::Unwrap(storage->p5_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType, - typename Bound4UnwrapTraits::ForwardType, - typename Bound5UnwrapTraits::ForwardType, - typename CallbackParamTraits<X6>::ForwardType x6)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6)); - } -}; - -// Arity 6 -> 0. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6> -struct Invoker<6, StorageType, R(X1, X2, X3, X4, X5, X6)> { - typedef R(RunType)(BindStateBase*); - - typedef R(UnboundRunType)(); - - static R Run(BindStateBase* base) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits; - typedef typename StorageType::Bound5UnwrapTraits Bound5UnwrapTraits; - typedef typename StorageType::Bound6UnwrapTraits Bound6UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - typename Bound4UnwrapTraits::ForwardType x4 = - Bound4UnwrapTraits::Unwrap(storage->p4_); - typename Bound5UnwrapTraits::ForwardType x5 = - Bound5UnwrapTraits::Unwrap(storage->p5_); - typename Bound6UnwrapTraits::ForwardType x6 = - Bound6UnwrapTraits::Unwrap(storage->p6_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType, - typename Bound4UnwrapTraits::ForwardType, - typename Bound5UnwrapTraits::ForwardType, - typename Bound6UnwrapTraits::ForwardType)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6)); - } -}; - -// Arity 7 -> 7. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6, typename X7> -struct Invoker<0, StorageType, R(X1, X2, X3, X4, X5, X6, X7)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X1>::ForwardType, - typename CallbackParamTraits<X2>::ForwardType, - typename CallbackParamTraits<X3>::ForwardType, - typename CallbackParamTraits<X4>::ForwardType, - typename CallbackParamTraits<X5>::ForwardType, - typename CallbackParamTraits<X6>::ForwardType, - typename CallbackParamTraits<X7>::ForwardType); - - typedef R(UnboundRunType)(X1, X2, X3, X4, X5, X6, X7); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X1>::ForwardType x1, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6, - typename CallbackParamTraits<X7>::ForwardType x7) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename CallbackParamTraits<X1>::ForwardType x1, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6, - typename CallbackParamTraits<X7>::ForwardType x7)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6), CallbackForward(x7)); - } -}; - -// Arity 7 -> 6. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6, typename X7> -struct Invoker<1, StorageType, R(X1, X2, X3, X4, X5, X6, X7)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X2>::ForwardType, - typename CallbackParamTraits<X3>::ForwardType, - typename CallbackParamTraits<X4>::ForwardType, - typename CallbackParamTraits<X5>::ForwardType, - typename CallbackParamTraits<X6>::ForwardType, - typename CallbackParamTraits<X7>::ForwardType); - - typedef R(UnboundRunType)(X2, X3, X4, X5, X6, X7); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6, - typename CallbackParamTraits<X7>::ForwardType x7) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename CallbackParamTraits<X2>::ForwardType x2, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6, - typename CallbackParamTraits<X7>::ForwardType x7)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6), CallbackForward(x7)); - } -}; - -// Arity 7 -> 5. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6, typename X7> -struct Invoker<2, StorageType, R(X1, X2, X3, X4, X5, X6, X7)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X3>::ForwardType, - typename CallbackParamTraits<X4>::ForwardType, - typename CallbackParamTraits<X5>::ForwardType, - typename CallbackParamTraits<X6>::ForwardType, - typename CallbackParamTraits<X7>::ForwardType); - - typedef R(UnboundRunType)(X3, X4, X5, X6, X7); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6, - typename CallbackParamTraits<X7>::ForwardType x7) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename CallbackParamTraits<X3>::ForwardType x3, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6, - typename CallbackParamTraits<X7>::ForwardType x7)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6), CallbackForward(x7)); - } -}; - -// Arity 7 -> 4. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6, typename X7> -struct Invoker<3, StorageType, R(X1, X2, X3, X4, X5, X6, X7)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X4>::ForwardType, - typename CallbackParamTraits<X5>::ForwardType, - typename CallbackParamTraits<X6>::ForwardType, - typename CallbackParamTraits<X7>::ForwardType); - - typedef R(UnboundRunType)(X4, X5, X6, X7); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6, - typename CallbackParamTraits<X7>::ForwardType x7) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType, - typename CallbackParamTraits<X4>::ForwardType x4, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6, - typename CallbackParamTraits<X7>::ForwardType x7)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6), CallbackForward(x7)); - } -}; - -// Arity 7 -> 3. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6, typename X7> -struct Invoker<4, StorageType, R(X1, X2, X3, X4, X5, X6, X7)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X5>::ForwardType, - typename CallbackParamTraits<X6>::ForwardType, - typename CallbackParamTraits<X7>::ForwardType); - - typedef R(UnboundRunType)(X5, X6, X7); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6, - typename CallbackParamTraits<X7>::ForwardType x7) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - typename Bound4UnwrapTraits::ForwardType x4 = - Bound4UnwrapTraits::Unwrap(storage->p4_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType, - typename Bound4UnwrapTraits::ForwardType, - typename CallbackParamTraits<X5>::ForwardType x5, - typename CallbackParamTraits<X6>::ForwardType x6, - typename CallbackParamTraits<X7>::ForwardType x7)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6), CallbackForward(x7)); - } -}; - -// Arity 7 -> 2. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6, typename X7> -struct Invoker<5, StorageType, R(X1, X2, X3, X4, X5, X6, X7)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X6>::ForwardType, - typename CallbackParamTraits<X7>::ForwardType); - - typedef R(UnboundRunType)(X6, X7); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X6>::ForwardType x6, - typename CallbackParamTraits<X7>::ForwardType x7) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits; - typedef typename StorageType::Bound5UnwrapTraits Bound5UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - typename Bound4UnwrapTraits::ForwardType x4 = - Bound4UnwrapTraits::Unwrap(storage->p4_); - typename Bound5UnwrapTraits::ForwardType x5 = - Bound5UnwrapTraits::Unwrap(storage->p5_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType, - typename Bound4UnwrapTraits::ForwardType, - typename Bound5UnwrapTraits::ForwardType, - typename CallbackParamTraits<X6>::ForwardType x6, - typename CallbackParamTraits<X7>::ForwardType x7)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6), CallbackForward(x7)); - } -}; - -// Arity 7 -> 1. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6, typename X7> -struct Invoker<6, StorageType, R(X1, X2, X3, X4, X5, X6, X7)> { - typedef R(RunType)(BindStateBase*, - typename CallbackParamTraits<X7>::ForwardType); - - typedef R(UnboundRunType)(X7); - - static R Run(BindStateBase* base, - typename CallbackParamTraits<X7>::ForwardType x7) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits; - typedef typename StorageType::Bound5UnwrapTraits Bound5UnwrapTraits; - typedef typename StorageType::Bound6UnwrapTraits Bound6UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - typename Bound4UnwrapTraits::ForwardType x4 = - Bound4UnwrapTraits::Unwrap(storage->p4_); - typename Bound5UnwrapTraits::ForwardType x5 = - Bound5UnwrapTraits::Unwrap(storage->p5_); - typename Bound6UnwrapTraits::ForwardType x6 = - Bound6UnwrapTraits::Unwrap(storage->p6_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType, - typename Bound4UnwrapTraits::ForwardType, - typename Bound5UnwrapTraits::ForwardType, - typename Bound6UnwrapTraits::ForwardType, - typename CallbackParamTraits<X7>::ForwardType x7)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6), CallbackForward(x7)); - } -}; - -// Arity 7 -> 0. -template <typename StorageType, typename R,typename X1, typename X2, - typename X3, typename X4, typename X5, typename X6, typename X7> -struct Invoker<7, StorageType, R(X1, X2, X3, X4, X5, X6, X7)> { - typedef R(RunType)(BindStateBase*); - - typedef R(UnboundRunType)(); - - static R Run(BindStateBase* base) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. - typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits; - typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits; - typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits; - typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits; - typedef typename StorageType::Bound5UnwrapTraits Bound5UnwrapTraits; - typedef typename StorageType::Bound6UnwrapTraits Bound6UnwrapTraits; - typedef typename StorageType::Bound7UnwrapTraits Bound7UnwrapTraits; - - typename Bound1UnwrapTraits::ForwardType x1 = - Bound1UnwrapTraits::Unwrap(storage->p1_); - typename Bound2UnwrapTraits::ForwardType x2 = - Bound2UnwrapTraits::Unwrap(storage->p2_); - typename Bound3UnwrapTraits::ForwardType x3 = - Bound3UnwrapTraits::Unwrap(storage->p3_); - typename Bound4UnwrapTraits::ForwardType x4 = - Bound4UnwrapTraits::Unwrap(storage->p4_); - typename Bound5UnwrapTraits::ForwardType x5 = - Bound5UnwrapTraits::Unwrap(storage->p5_); - typename Bound6UnwrapTraits::ForwardType x6 = - Bound6UnwrapTraits::Unwrap(storage->p6_); - typename Bound7UnwrapTraits::ForwardType x7 = - Bound7UnwrapTraits::Unwrap(storage->p7_); - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void(typename Bound1UnwrapTraits::ForwardType, - typename Bound2UnwrapTraits::ForwardType, - typename Bound3UnwrapTraits::ForwardType, - typename Bound4UnwrapTraits::ForwardType, - typename Bound5UnwrapTraits::ForwardType, - typename Bound6UnwrapTraits::ForwardType, - typename Bound7UnwrapTraits::ForwardType)> - ::MakeItSo(storage->runnable_, CallbackForward(x1), - CallbackForward(x2), CallbackForward(x3), - CallbackForward(x4), CallbackForward(x5), - CallbackForward(x6), CallbackForward(x7)); + return InvokeHelperType::MakeItSo( + storage->runnable_, + Unwrappers::Unwrap(get<bound_indices>(storage->bound_args_))..., + CallbackForward(unbound_args)...); } }; @@ -1837,275 +360,52 @@ struct Invoker<7, StorageType, R(X1, X2, X3, X4, X5, X6, X7)> { // // BoundArgsType contains the storage type for all the bound arguments by // (ab)using a function type. -template <typename Runnable, typename RunType, typename BoundArgsType> +template <typename Runnable, typename RunType, typename BoundArgList> struct BindState; -template <typename Runnable, typename RunType> -struct BindState<Runnable, RunType, void()> : public BindStateBase { - typedef Runnable RunnableType; - typedef false_type IsWeakCall; - typedef Invoker<0, BindState, RunType> InvokerType; - typedef typename InvokerType::UnboundRunType UnboundRunType; - explicit BindState(const Runnable& runnable) - : runnable_(runnable) { - } - - RunnableType runnable_; - +template <typename Runnable, + typename R, typename... Args, + typename... BoundArgs> +struct BindState<Runnable, R(Args...), TypeList<BoundArgs...>> + : public BindStateBase { private: - ~BindState() override { } + using StorageType = BindState<Runnable, R(Args...), TypeList<BoundArgs...>>; + using RunnableType = Runnable; -}; - -template <typename Runnable, typename RunType, typename P1> -struct BindState<Runnable, RunType, void(P1)> : public BindStateBase { - typedef Runnable RunnableType; - typedef IsWeakMethod<HasIsMethodTag<Runnable>::value, P1> IsWeakCall; - typedef Invoker<1, BindState, RunType> InvokerType; - typedef typename InvokerType::UnboundRunType UnboundRunType; - - // Convenience typedefs for bound argument types. - typedef UnwrapTraits<P1> Bound1UnwrapTraits; - - BindState(const Runnable& runnable, const P1& p1) - : runnable_(runnable), - p1_(p1) { - MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::AddRef(p1_); - } - - RunnableType runnable_; - P1 p1_; - - private: - ~BindState() override { MaybeRefcount<HasIsMethodTag<Runnable>::value, - P1>::Release(p1_); } - -}; - -template <typename Runnable, typename RunType, typename P1, typename P2> -struct BindState<Runnable, RunType, void(P1, P2)> : public BindStateBase { - typedef Runnable RunnableType; - typedef IsWeakMethod<HasIsMethodTag<Runnable>::value, P1> IsWeakCall; - typedef Invoker<2, BindState, RunType> InvokerType; - typedef typename InvokerType::UnboundRunType UnboundRunType; - - // Convenience typedefs for bound argument types. - typedef UnwrapTraits<P1> Bound1UnwrapTraits; - typedef UnwrapTraits<P2> Bound2UnwrapTraits; - - BindState(const Runnable& runnable, const P1& p1, const P2& p2) - : runnable_(runnable), - p1_(p1), - p2_(p2) { - MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::AddRef(p1_); - } - - RunnableType runnable_; - P1 p1_; - P2 p2_; - - private: - ~BindState() override { MaybeRefcount<HasIsMethodTag<Runnable>::value, - P1>::Release(p1_); } - -}; - -template <typename Runnable, typename RunType, typename P1, typename P2, - typename P3> -struct BindState<Runnable, RunType, void(P1, P2, P3)> : public BindStateBase { - typedef Runnable RunnableType; - typedef IsWeakMethod<HasIsMethodTag<Runnable>::value, P1> IsWeakCall; - typedef Invoker<3, BindState, RunType> InvokerType; - typedef typename InvokerType::UnboundRunType UnboundRunType; - - // Convenience typedefs for bound argument types. - typedef UnwrapTraits<P1> Bound1UnwrapTraits; - typedef UnwrapTraits<P2> Bound2UnwrapTraits; - typedef UnwrapTraits<P3> Bound3UnwrapTraits; - - BindState(const Runnable& runnable, const P1& p1, const P2& p2, const P3& p3) - : runnable_(runnable), - p1_(p1), - p2_(p2), - p3_(p3) { - MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::AddRef(p1_); - } - - RunnableType runnable_; - P1 p1_; - P2 p2_; - P3 p3_; - - private: - ~BindState() override { MaybeRefcount<HasIsMethodTag<Runnable>::value, - P1>::Release(p1_); } - -}; + // true_type if Runnable is a method invocation and the first bound argument + // is a WeakPtr. + using IsWeakCall = + IsWeakMethod<HasIsMethodTag<Runnable>::value, BoundArgs...>; -template <typename Runnable, typename RunType, typename P1, typename P2, - typename P3, typename P4> -struct BindState<Runnable, RunType, void(P1, P2, P3, - P4)> : public BindStateBase { - typedef Runnable RunnableType; - typedef IsWeakMethod<HasIsMethodTag<Runnable>::value, P1> IsWeakCall; - typedef Invoker<4, BindState, RunType> InvokerType; - typedef typename InvokerType::UnboundRunType UnboundRunType; + using BoundIndices = MakeIndexSequence<sizeof...(BoundArgs)>; + using Unwrappers = TypeList<UnwrapTraits<BoundArgs>...>; + using UnboundForwardArgs = DropTypeListItem< + sizeof...(BoundArgs), + TypeList<typename CallbackParamTraits<Args>::ForwardType...>>; + using UnboundForwardRunType = MakeFunctionType<R, UnboundForwardArgs>; - // Convenience typedefs for bound argument types. - typedef UnwrapTraits<P1> Bound1UnwrapTraits; - typedef UnwrapTraits<P2> Bound2UnwrapTraits; - typedef UnwrapTraits<P3> Bound3UnwrapTraits; - typedef UnwrapTraits<P4> Bound4UnwrapTraits; + using InvokeHelperArgs = ConcatTypeLists< + TypeList<typename UnwrapTraits<BoundArgs>::ForwardType...>, + UnboundForwardArgs>; + using InvokeHelperType = + InvokeHelper<IsWeakCall::value, R, Runnable, InvokeHelperArgs>; - BindState(const Runnable& runnable, const P1& p1, const P2& p2, const P3& p3, - const P4& p4) - : runnable_(runnable), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4) { - MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::AddRef(p1_); - } - - RunnableType runnable_; - P1 p1_; - P2 p2_; - P3 p3_; - P4 p4_; - - private: - ~BindState() override { MaybeRefcount<HasIsMethodTag<Runnable>::value, - P1>::Release(p1_); } - -}; - -template <typename Runnable, typename RunType, typename P1, typename P2, - typename P3, typename P4, typename P5> -struct BindState<Runnable, RunType, void(P1, P2, P3, P4, - P5)> : public BindStateBase { - typedef Runnable RunnableType; - typedef IsWeakMethod<HasIsMethodTag<Runnable>::value, P1> IsWeakCall; - typedef Invoker<5, BindState, RunType> InvokerType; - typedef typename InvokerType::UnboundRunType UnboundRunType; + using UnboundArgs = DropTypeListItem<sizeof...(BoundArgs), TypeList<Args...>>; - // Convenience typedefs for bound argument types. - typedef UnwrapTraits<P1> Bound1UnwrapTraits; - typedef UnwrapTraits<P2> Bound2UnwrapTraits; - typedef UnwrapTraits<P3> Bound3UnwrapTraits; - typedef UnwrapTraits<P4> Bound4UnwrapTraits; - typedef UnwrapTraits<P5> Bound5UnwrapTraits; - - BindState(const Runnable& runnable, const P1& p1, const P2& p2, const P3& p3, - const P4& p4, const P5& p5) - : runnable_(runnable), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5) { - MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::AddRef(p1_); - } - - RunnableType runnable_; - P1 p1_; - P2 p2_; - P3 p3_; - P4 p4_; - P5 p5_; - - private: - ~BindState() override { MaybeRefcount<HasIsMethodTag<Runnable>::value, - P1>::Release(p1_); } - -}; - -template <typename Runnable, typename RunType, typename P1, typename P2, - typename P3, typename P4, typename P5, typename P6> -struct BindState<Runnable, RunType, void(P1, P2, P3, P4, P5, - P6)> : public BindStateBase { - typedef Runnable RunnableType; - typedef IsWeakMethod<HasIsMethodTag<Runnable>::value, P1> IsWeakCall; - typedef Invoker<6, BindState, RunType> InvokerType; - typedef typename InvokerType::UnboundRunType UnboundRunType; - - // Convenience typedefs for bound argument types. - typedef UnwrapTraits<P1> Bound1UnwrapTraits; - typedef UnwrapTraits<P2> Bound2UnwrapTraits; - typedef UnwrapTraits<P3> Bound3UnwrapTraits; - typedef UnwrapTraits<P4> Bound4UnwrapTraits; - typedef UnwrapTraits<P5> Bound5UnwrapTraits; - typedef UnwrapTraits<P6> Bound6UnwrapTraits; - - BindState(const Runnable& runnable, const P1& p1, const P2& p2, const P3& p3, - const P4& p4, const P5& p5, const P6& p6) - : runnable_(runnable), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5), - p6_(p6) { - MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::AddRef(p1_); - } - - RunnableType runnable_; - P1 p1_; - P2 p2_; - P3 p3_; - P4 p4_; - P5 p5_; - P6 p6_; - - private: - ~BindState() override { MaybeRefcount<HasIsMethodTag<Runnable>::value, - P1>::Release(p1_); } - -}; - -template <typename Runnable, typename RunType, typename P1, typename P2, - typename P3, typename P4, typename P5, typename P6, typename P7> -struct BindState<Runnable, RunType, void(P1, P2, P3, P4, P5, P6, - P7)> : public BindStateBase { - typedef Runnable RunnableType; - typedef IsWeakMethod<HasIsMethodTag<Runnable>::value, P1> IsWeakCall; - typedef Invoker<7, BindState, RunType> InvokerType; - typedef typename InvokerType::UnboundRunType UnboundRunType; - - // Convenience typedefs for bound argument types. - typedef UnwrapTraits<P1> Bound1UnwrapTraits; - typedef UnwrapTraits<P2> Bound2UnwrapTraits; - typedef UnwrapTraits<P3> Bound3UnwrapTraits; - typedef UnwrapTraits<P4> Bound4UnwrapTraits; - typedef UnwrapTraits<P5> Bound5UnwrapTraits; - typedef UnwrapTraits<P6> Bound6UnwrapTraits; - typedef UnwrapTraits<P7> Bound7UnwrapTraits; + public: + using InvokerType = Invoker<BoundIndices, StorageType, Unwrappers, + InvokeHelperType, UnboundForwardRunType>; + using UnboundRunType = MakeFunctionType<R, UnboundArgs>; - BindState(const Runnable& runnable, const P1& p1, const P2& p2, const P3& p3, - const P4& p4, const P5& p5, const P6& p6, const P7& p7) - : runnable_(runnable), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5), - p6_(p6), - p7_(p7) { - MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::AddRef(p1_); - } + BindState(const Runnable& runnable, const BoundArgs&... bound_args) + : runnable_(runnable), ref_(bound_args...), bound_args_(bound_args...) {} RunnableType runnable_; - P1 p1_; - P2 p2_; - P3 p3_; - P4 p4_; - P5 p5_; - P6 p6_; - P7 p7_; + MaybeScopedRefPtr<HasIsMethodTag<Runnable>::value, BoundArgs...> ref_; + Tuple<BoundArgs...> bound_args_; private: - ~BindState() override { MaybeRefcount<HasIsMethodTag<Runnable>::value, - P1>::Release(p1_); } - + ~BindState() override {} }; } // namespace internal diff --git a/base/bind_internal.h.pump b/base/bind_internal.h.pump deleted file mode 100644 index 0ed3ca2..0000000 --- a/base/bind_internal.h.pump +++ /dev/null @@ -1,516 +0,0 @@ -$$ This is a pump file for generating file templates. Pump is a python -$$ script that is part of the Google Test suite of utilities. Description -$$ can be found here: -$$ -$$ http://code.google.com/p/googletest/wiki/PumpManual -$$ - -$$ See comment for MAX_ARITY in base/bind.h.pump. -$var MAX_ARITY = 7 -$range ARITY 0..MAX_ARITY - -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_BIND_INTERNAL_H_ -#define BASE_BIND_INTERNAL_H_ - -#include "base/bind_helpers.h" -#include "base/callback_internal.h" -#include "base/memory/raw_scoped_refptr_mismatch_checker.h" -#include "base/memory/weak_ptr.h" -#include "base/template_util.h" -#include "build/build_config.h" - -#if defined(OS_WIN) -#include "base/bind_internal_win.h" -#endif - -namespace base { -namespace internal { - -// See base/callback.h for user documentation. -// -// -// CONCEPTS: -// Runnable -- A type (really a type class) that has a single Run() method -// and a RunType typedef that corresponds to the type of Run(). -// A Runnable can declare that it should treated like a method -// call by including a typedef named IsMethod. The value of -// this typedef is NOT inspected, only the existence. When a -// Runnable declares itself a method, Bind() will enforce special -// refcounting + WeakPtr handling semantics for the first -// parameter which is expected to be an object. -// Functor -- A copyable type representing something that should be called. -// All function pointers, Callback<>, and Runnables are functors -// even if the invocation syntax differs. -// RunType -- A function type (as opposed to function _pointer_ type) for -// a Run() function. Usually just a convenience typedef. -// (Bound)ArgsType -- A function type that is being (ab)used to store the -// types of set of arguments. The "return" type is always -// void here. We use this hack so that we do not need -// a new type name for each arity of type. (eg., -// BindState1, BindState2). This makes forward -// declarations and friending much much easier. -// -// Types: -// RunnableAdapter<> -- Wraps the various "function" pointer types into an -// object that adheres to the Runnable interface. -// FunctionTraits<> -- Type traits that unwrap a function signature into a -// a set of easier to use typedefs. Used mainly for -// compile time asserts. -// There are |ARITY| FunctionTraits types. -// ForceVoidReturn<> -- Helper class for translating function signatures to -// equivalent forms with a "void" return type. -// FunctorTraits<> -- Type traits used determine the correct RunType and -// RunnableType for a Functor. This is where function -// signature adapters are applied. -// MakeRunnable<> -- Takes a Functor and returns an object in the Runnable -// type class that represents the underlying Functor. -// There are |O(1)| MakeRunnable types. -// InvokeHelper<> -- Take a Runnable + arguments and actully invokes it. -// Handle the differing syntaxes needed for WeakPtr<> support, -// and for ignoring return values. This is separate from -// Invoker to avoid creating multiple version of Invoker<> -// which grows at O(n^2) with the arity. -// Invoker<> -- Unwraps the curried parameters and executes the Runnable. -// There are |(ARITY^2 + ARITY)/2| Invoketypes. -// BindState<> -- Stores the curried parameters, and is the main entry point -// into the Bind() system, doing most of the type resolution. -// There are ARITY BindState types. - -// HasNonConstReferenceParam selects true_type when any of the parameters in -// |Sig| is a non-const reference. -// Implementation note: This non-specialized case handles zero-arity case only. -// Non-zero-arity cases should be handled by the specialization below. -template <typename Sig> -struct HasNonConstReferenceParam : false_type {}; - -// Implementation note: Select true_type if the first parameter is a non-const -// reference. Otherwise, skip the first parameter and check rest of parameters -// recursively. -template <typename R, typename T, typename... Args> -struct HasNonConstReferenceParam<R(T, Args...)> - : SelectType<is_non_const_reference<T>::value, - true_type, - HasNonConstReferenceParam<R(Args...)>>::Type {}; - -// HasRefCountedTypeAsRawPtr selects true_type when any of the |Args| is a raw -// pointer to a RefCounted type. -// Implementation note: This non-specialized case handles zero-arity case only. -// Non-zero-arity cases should be handled by the specialization below. -template <typename... Args> -struct HasRefCountedTypeAsRawPtr : false_type {}; - -// Implementation note: Select true_type if the first parameter is a raw pointer -// to a RefCounted type. Otherwise, skip the first parameter and check rest of -// parameters recursively. -template <typename T, typename... Args> -struct HasRefCountedTypeAsRawPtr<T, Args...> - : SelectType<NeedsScopedRefptrButGetsRawPtr<T>::value, - true_type, - HasRefCountedTypeAsRawPtr<Args...>>::Type {}; - -// BindsArrayToFirstArg selects true_type when |is_method| is true and the first -// item of |Args| is an array type. -// Implementation note: This non-specialized case handles !is_method case and -// zero-arity case only. Other cases should be handled by the specialization -// below. -template <bool is_method, typename... Args> -struct BindsArrayToFirstArg : false_type {}; - -template <typename T, typename... Args> -struct BindsArrayToFirstArg<true, T, Args...> : is_array<T> {}; - -// HasRefCountedParamAsRawPtr is the same to HasRefCountedTypeAsRawPtr except -// when |is_method| is true HasRefCountedParamAsRawPtr skips the first argument. -// Implementation note: This non-specialized case handles !is_method case and -// zero-arity case only. Other cases should be handled by the specialization -// below. -template <bool is_method, typename... Args> -struct HasRefCountedParamAsRawPtr : HasRefCountedTypeAsRawPtr<Args...> {}; - -template <typename T, typename... Args> -struct HasRefCountedParamAsRawPtr<true, T, Args...> - : HasRefCountedTypeAsRawPtr<Args...> {}; - -// RunnableAdapter<> -// -// The RunnableAdapter<> templates provide a uniform interface for invoking -// a function pointer, method pointer, or const method pointer. The adapter -// exposes a Run() method with an appropriate signature. Using this wrapper -// allows for writing code that supports all three pointer types without -// undue repetition. Without it, a lot of code would need to be repeated 3 -// times. -// -// For method pointers and const method pointers the first argument to Run() -// is considered to be the received of the method. This is similar to STL's -// mem_fun(). -// -// This class also exposes a RunType typedef that is the function type of the -// Run() function. -// -// If and only if the wrapper contains a method or const method pointer, an -// IsMethod typedef is exposed. The existence of this typedef (NOT the value) -// marks that the wrapper should be considered a method wrapper. - -template <typename Functor> -class RunnableAdapter; - -// Function. -template <typename R, typename... Args> -class RunnableAdapter<R(*)(Args...)> { - public: - typedef R (RunType)(Args...); - - explicit RunnableAdapter(R(*function)(Args...)) - : function_(function) { - } - - R Run(typename CallbackParamTraits<Args>::ForwardType... args) { - return function_(CallbackForward(args)...); - } - - private: - R (*function_)(Args...); -}; - -// Method. -template <typename R, typename T, typename... Args> -class RunnableAdapter<R(T::*)(Args...)> { - public: - typedef R (RunType)(T*, Args...); - typedef true_type IsMethod; - - explicit RunnableAdapter(R(T::*method)(Args...)) - : method_(method) { - } - - R Run(T* object, typename CallbackParamTraits<Args>::ForwardType... args) { - return (object->*method_)(CallbackForward(args)...); - } - - private: - R (T::*method_)(Args...); -}; - -// Const Method. -template <typename R, typename T, typename... Args> -class RunnableAdapter<R(T::*)(Args...) const> { - public: - typedef R (RunType)(const T*, Args...); - typedef true_type IsMethod; - - explicit RunnableAdapter(R(T::*method)(Args...) const) - : method_(method) { - } - - R Run(const T* object, - typename CallbackParamTraits<Args>::ForwardType... args) { - return (object->*method_)(CallbackForward(args)...); - } - - private: - R (T::*method_)(Args...) const; -}; - -// TODO(tzik): Remove FunctionTraits after we finish removing bind.pump. -// FunctionTraits<> -// -// Breaks a function signature apart into typedefs for easier introspection. -template <typename Sig> -struct FunctionTraits; - -$for ARITY [[ -$range ARG 1..ARITY - -template <typename R[[]] -$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]> -struct FunctionTraits<R($for ARG , [[A$(ARG)]])> { - typedef R ReturnType; -$for ARG [[ - - typedef A$(ARG) A$(ARG)Type; -]] - -}; - -]] - - -// ForceVoidReturn<> -// -// Set of templates that support forcing the function return type to void. -template <typename Sig> -struct ForceVoidReturn; - -template <typename R, typename... Args> -struct ForceVoidReturn<R(Args...)> { - typedef void(RunType)(Args...); -}; - - -// FunctorTraits<> -// -// See description at top of file. -template <typename T> -struct FunctorTraits { - typedef RunnableAdapter<T> RunnableType; - typedef typename RunnableType::RunType RunType; -}; - -template <typename T> -struct FunctorTraits<IgnoreResultHelper<T> > { - typedef typename FunctorTraits<T>::RunnableType RunnableType; - typedef typename ForceVoidReturn< - typename RunnableType::RunType>::RunType RunType; -}; - -template <typename T> -struct FunctorTraits<Callback<T> > { - typedef Callback<T> RunnableType; - typedef typename Callback<T>::RunType RunType; -}; - - -// MakeRunnable<> -// -// Converts a passed in functor to a RunnableType using type inference. - -template <typename T> -typename FunctorTraits<T>::RunnableType MakeRunnable(const T& t) { - return RunnableAdapter<T>(t); -} - -template <typename T> -typename FunctorTraits<T>::RunnableType -MakeRunnable(const IgnoreResultHelper<T>& t) { - return MakeRunnable(t.functor_); -} - -template <typename T> -const typename FunctorTraits<Callback<T> >::RunnableType& -MakeRunnable(const Callback<T>& t) { - DCHECK(!t.is_null()); - return t; -} - - -// InvokeHelper<> -// -// There are 3 logical InvokeHelper<> specializations: normal, void-return, -// WeakCalls. -// -// The normal type just calls the underlying runnable. -// -// We need a InvokeHelper to handle void return types in order to support -// IgnoreResult(). Normally, if the Runnable's RunType had a void return, -// the template system would just accept "return functor.Run()" ignoring -// the fact that a void function is being used with return. This piece of -// sugar breaks though when the Runnable's RunType is not void. Thus, we -// need a partial specialization to change the syntax to drop the "return" -// from the invocation call. -// -// WeakCalls similarly need special syntax that is applied to the first -// argument to check if they should no-op themselves. -template <bool IsWeakCall, typename ReturnType, typename Runnable, - typename ArgsType> -struct InvokeHelper; - -template <typename ReturnType, typename Runnable, typename... Args> -struct InvokeHelper<false, ReturnType, Runnable, - void(Args...)> { - static ReturnType MakeItSo(Runnable runnable, Args... args) { - return runnable.Run(CallbackForward(args)...); - } -}; - -template <typename Runnable, typename... Args> -struct InvokeHelper<false, void, Runnable, void(Args...)> { - static void MakeItSo(Runnable runnable, Args... args) { - runnable.Run(CallbackForward(args)...); - } -}; - -template <typename Runnable, typename BoundWeakPtr, typename... Args> -struct InvokeHelper<true, void, Runnable, void(BoundWeakPtr, Args...)> { - static void MakeItSo(Runnable runnable, BoundWeakPtr weak_ptr, Args... args) { - if (!weak_ptr.get()) { - return; - } - runnable.Run(weak_ptr.get(), CallbackForward(args)...); - } -}; - -#if !defined(_MSC_VER) - -template <typename ReturnType, typename Runnable, typename ArgsType> -struct InvokeHelper<true, ReturnType, Runnable, ArgsType> { - // WeakCalls are only supported for functions with a void return type. - // Otherwise, the function result would be undefined if the the WeakPtr<> - // is invalidated. - COMPILE_ASSERT(is_void<ReturnType>::value, - weak_ptrs_can_only_bind_to_methods_without_return_values); -}; - -#endif - -// Invoker<> -// -// See description at the top of the file. -template <int NumBound, typename Storage, typename RunType> -struct Invoker; - -$for ARITY [[ - -$$ Number of bound arguments. -$range BOUND 0..ARITY -$for BOUND [[ - -$var UNBOUND = ARITY - BOUND -$range ARG 1..ARITY -$range BOUND_ARG 1..BOUND -$range UNBOUND_ARG (ARITY - UNBOUND + 1)..ARITY - -// Arity $(ARITY) -> $(UNBOUND). -template <typename StorageType, typename R[[]] -$if ARITY > 0 [[,]][[]] -$for ARG , [[typename X$(ARG)]]> -struct Invoker<$(BOUND), StorageType, R($for ARG , [[X$(ARG)]])> { - typedef R(RunType)(BindStateBase*[[]] -$if UNBOUND != 0 [[, ]] -$for UNBOUND_ARG , [[typename CallbackParamTraits<X$(UNBOUND_ARG)>::ForwardType]]); - - typedef R(UnboundRunType)($for UNBOUND_ARG , [[X$(UNBOUND_ARG)]]); - - static R Run(BindStateBase* base[[]] -$if UNBOUND != 0 [[, ]][[]] -$for UNBOUND_ARG , [[ -typename CallbackParamTraits<X$(UNBOUND_ARG)>::ForwardType x$(UNBOUND_ARG) -]][[]] -) { - StorageType* storage = static_cast<StorageType*>(base); - - // Local references to make debugger stepping easier. If in a debugger, - // you really want to warp ahead and step through the - // InvokeHelper<>::MakeItSo() call below. -$for BOUND_ARG -[[ - - typedef typename StorageType::Bound$(BOUND_ARG)UnwrapTraits Bound$(BOUND_ARG)UnwrapTraits; -]] - - -$for BOUND_ARG -[[ - - typename Bound$(BOUND_ARG)UnwrapTraits::ForwardType x$(BOUND_ARG) = - Bound$(BOUND_ARG)UnwrapTraits::Unwrap(storage->p$(BOUND_ARG)_); -]] - - return InvokeHelper<StorageType::IsWeakCall::value, R, - typename StorageType::RunnableType, - void( -$for BOUND_ARG , [[ -typename Bound$(BOUND_ARG)UnwrapTraits::ForwardType -]] - -$if UNBOUND > 0 [[$if BOUND > 0 [[, ]]]][[]] - -$for UNBOUND_ARG , [[ -typename CallbackParamTraits<X$(UNBOUND_ARG)>::ForwardType x$(UNBOUND_ARG) -]] -)> - ::MakeItSo(storage->runnable_ -$if ARITY > 0[[, ]] $for ARG , [[CallbackForward(x$(ARG))]]); - } -}; - -]] $$ for BOUND -]] $$ for ARITY - - -// BindState<> -// -// This stores all the state passed into Bind() and is also where most -// of the template resolution magic occurs. -// -// Runnable is the functor we are binding arguments to. -// RunType is type of the Run() function that the Invoker<> should use. -// Normally, this is the same as the RunType of the Runnable, but it can -// be different if an adapter like IgnoreResult() has been used. -// -// BoundArgsType contains the storage type for all the bound arguments by -// (ab)using a function type. -template <typename Runnable, typename RunType, typename BoundArgsType> -struct BindState; - -$for ARITY [[ -$range ARG 1..ARITY - -template <typename Runnable, typename RunType[[]] -$if ARITY > 0[[, ]] $for ARG , [[typename P$(ARG)]]> -struct BindState<Runnable, RunType, void($for ARG , [[P$(ARG)]])> : public BindStateBase { - typedef Runnable RunnableType; - -$if ARITY > 0 [[ - typedef IsWeakMethod<HasIsMethodTag<Runnable>::value, P1> IsWeakCall; -]] $else [[ - typedef false_type IsWeakCall; -]] - - typedef Invoker<$(ARITY), BindState, RunType> InvokerType; - typedef typename InvokerType::UnboundRunType UnboundRunType; - -$if ARITY > 0 [[ - - // Convenience typedefs for bound argument types. - -$for ARG [[ - typedef UnwrapTraits<P$(ARG)> Bound$(ARG)UnwrapTraits; - -]] $$ for ARG - - -]] $$ if ARITY > 0 - -$$ The extra [[ ]] is needed to massage spacing. Silly pump.py. -[[ ]]$if ARITY == 0 [[explicit ]]BindState(const Runnable& runnable -$if ARITY > 0 [[, ]] $for ARG , [[const P$(ARG)& p$(ARG)]]) - : runnable_(runnable)[[]] -$if ARITY == 0 [[ - { - -]] $else [[ -, $for ARG , [[ - - p$(ARG)_(p$(ARG)) -]] { - MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::AddRef(p1_); - -]] - } - - RunnableType runnable_; - -$for ARG [[ - P$(ARG) p$(ARG)_; - -]] - - private: - ~BindState() override { -$if ARITY > 0 [[ - MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::Release(p1_); -]] - } - -}; - -]] $$ for ARITY - -} // namespace internal -} // namespace base - -#endif // BASE_BIND_INTERNAL_H_ diff --git a/base/bind_unittest.nc b/base/bind_unittest.nc index 33b5f5c..2596386 100644 --- a/base/bind_unittest.nc +++ b/base/bind_unittest.nc @@ -190,7 +190,7 @@ void WontCompile() { weak_ptr_with_non_void_return_type.Run(); } -#elif defined(NCTEST_DISALLOW_ASSIGN_DIFFERENT_TYPES) // [r"fatal error: no viable conversion from 'Callback<typename internal::BindState<typename internal::FunctorTraits<void \(\*\)\(int\)>::RunnableType, typename internal::FunctorTraits<void \(\*\)\(int\)>::RunType, void \(\)>::UnboundRunType>' to 'Callback<void \(\)>'"] +#elif defined(NCTEST_DISALLOW_ASSIGN_DIFFERENT_TYPES) // [r"fatal error: no viable conversion from 'Callback<typename internal::BindState<typename internal::FunctorTraits<void \(\*\)\(int\)>::RunnableType, typename internal::FunctorTraits<void \(\*\)\(int\)>::RunType, internal::TypeList<> >::UnboundRunType>' to 'Callback<void \(\)>'"] // Bind result cannot be assigned to Callbacks with a mismatching type. void WontCompile() { |