From c821499285f70fac3090ff79850a0f2fdacec870 Mon Sep 17 00:00:00 2001 From: tzik Date: Thu, 20 Nov 2014 02:09:45 -0800 Subject: [Base] Use variadic template for helpers in bind_internal.h This CL removes generated code for * RunnableAdapter * ForceVoidReturn * FunctorTraits * InvokeHelper from base/bind_internal.h. BUG=433164 Review URL: https://codereview.chromium.org/621773002 Cr-Commit-Position: refs/heads/master@{#304997} --- base/bind_internal.h.pump | 123 ++++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 82 deletions(-) (limited to 'base/bind_internal.h.pump') diff --git a/base/bind_internal.h.pump b/base/bind_internal.h.pump index f632b99..9ddca47 100644 --- a/base/bind_internal.h.pump +++ b/base/bind_internal.h.pump @@ -57,18 +57,15 @@ namespace internal { // Types: // RunnableAdapter<> -- Wraps the various "function" pointer types into an // object that adheres to the Runnable interface. -// There are |3*ARITY| RunnableAdapter types. // 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. -// There are |ARITY| ForceVoidReturn types. // FunctorTraits<> -- Type traits used determine the correct RunType and // RunnableType for a Functor. This is where function // signature adapters are applied. -// There are |ARITY| ForceVoidReturn types. // MakeRunnable<> -- Takes a Functor and returns an object in the Runnable // type class that represents the underlying Functor. // There are |O(1)| MakeRunnable types. @@ -77,7 +74,6 @@ namespace internal { // 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. -// There are |k*ARITY| InvokeHelper types. // 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 @@ -107,75 +103,64 @@ namespace internal { template class RunnableAdapter; -$for ARITY [[ -$range ARG 1..ARITY - -// Function: Arity $(ARITY). -template 0[[, ]] $for ARG , [[typename A$(ARG)]]> -class RunnableAdapter { +// Function. +template +class RunnableAdapter { public: - typedef R (RunType)($for ARG , [[A$(ARG)]]); + typedef R (RunType)(Args...); - explicit RunnableAdapter(R(*function)($for ARG , [[A$(ARG)]])) + explicit RunnableAdapter(R(*function)(Args...)) : function_(function) { } - R Run($for ARG , [[typename CallbackParamTraits::ForwardType a$(ARG)]]) { - return function_($for ARG , [[CallbackForward(a$(ARG))]]); + R Run(typename CallbackParamTraits::ForwardType... args) { + return function_(CallbackForward(args)...); } private: - R (*function_)($for ARG , [[A$(ARG)]]); + R (*function_)(Args...); }; -// Method: Arity $(ARITY). -template 0[[, ]] $for ARG , [[typename A$(ARG)]]> -class RunnableAdapter { +// Method. +template +class RunnableAdapter { public: - typedef R (RunType)(T*[[]] -$if ARITY > 0[[, ]] $for ARG , [[A$(ARG)]]); + typedef R (RunType)(T*, Args...); typedef true_type IsMethod; - explicit RunnableAdapter(R(T::*method)($for ARG , [[A$(ARG)]])) + explicit RunnableAdapter(R(T::*method)(Args...)) : method_(method) { } - R Run(T* object[[]] -$if ARITY > 0[[, ]] $for ARG, [[typename CallbackParamTraits::ForwardType a$(ARG)]]) { - return (object->*method_)($for ARG , [[CallbackForward(a$(ARG))]]); + R Run(T* object, typename CallbackParamTraits::ForwardType... args) { + return (object->*method_)(CallbackForward(args)...); } private: - R (T::*method_)($for ARG , [[A$(ARG)]]); + R (T::*method_)(Args...); }; -// Const Method: Arity $(ARITY). -template 0[[, ]] $for ARG , [[typename A$(ARG)]]> -class RunnableAdapter { +// Const Method. +template +class RunnableAdapter { public: - typedef R (RunType)(const T*[[]] -$if ARITY > 0[[, ]] $for ARG , [[A$(ARG)]]); + typedef R (RunType)(const T*, Args...); typedef true_type IsMethod; - explicit RunnableAdapter(R(T::*method)($for ARG , [[A$(ARG)]]) const) + explicit RunnableAdapter(R(T::*method)(Args...) const) : method_(method) { } - R Run(const T* object[[]] -$if ARITY > 0[[, ]] $for ARG, [[typename CallbackParamTraits::ForwardType a$(ARG)]]) { - return (object->*method_)($for ARG , [[CallbackForward(a$(ARG))]]); + R Run(const T* object, + typename CallbackParamTraits::ForwardType... args) { + return (object->*method_)(CallbackForward(args)...); } private: - R (T::*method_)($for ARG , [[A$(ARG)]]) const; + R (T::*method_)(Args...) const; }; -]] $$ for ARITY - - +// TODO(tzik): Remove FunctionTraits after we finish removing bind.pump. // FunctionTraits<> // // Breaks a function signature apart into typedefs for easier introspection. @@ -205,17 +190,11 @@ $for ARG [[ template struct ForceVoidReturn; -$for ARITY [[ -$range ARG 1..ARITY - -template 0[[, ]] $for ARG , [[typename A$(ARG)]]> -struct ForceVoidReturn { - typedef void(RunType)($for ARG , [[A$(ARG)]]); +template +struct ForceVoidReturn { + typedef void(RunType)(Args...); }; -]] $$ for ARITY - // FunctorTraits<> // @@ -284,51 +263,31 @@ template struct InvokeHelper; -$for ARITY [[ -$range ARG 1..ARITY -$range WEAKCALL_ARG 2..ARITY - -template 0 [[,]] $for ARG , [[typename A$(ARG)]]> +template struct InvokeHelper { - static ReturnType MakeItSo(Runnable runnable[[]] -$if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) { - return runnable.Run($for ARG , [[CallbackForward(a$(ARG))]]); + void(Args...)> { + static ReturnType MakeItSo(Runnable runnable, Args... args) { + return runnable.Run(CallbackForward(args)...); } }; -template 0 [[,]] $for ARG , [[typename A$(ARG)]]> -struct InvokeHelper { - static void MakeItSo(Runnable runnable[[]] -$if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) { - runnable.Run($for ARG , [[CallbackForward(a$(ARG))]]); +template +struct InvokeHelper { + static void MakeItSo(Runnable runnable, Args... args) { + runnable.Run(CallbackForward(args)...); } }; -$if ARITY > 0 [[ - -template 1[[, ]] $for WEAKCALL_ARG , [[typename A$(WEAKCALL_ARG)]]> -struct InvokeHelper 1[[, ]] $for WEAKCALL_ARG , [[A$(WEAKCALL_ARG)]])> { - static void MakeItSo(Runnable runnable, BoundWeakPtr weak_ptr -$if ARITY > 1[[, ]] $for WEAKCALL_ARG , [[A$(WEAKCALL_ARG) a$(WEAKCALL_ARG)]]) { +template +struct InvokeHelper { + static void MakeItSo(Runnable runnable, BoundWeakPtr weak_ptr, Args... args) { if (!weak_ptr.get()) { return; } - runnable.Run(weak_ptr.get() -$if ARITY > 1[[, ]] $for WEAKCALL_ARG , [[CallbackForward(a$(WEAKCALL_ARG))]]); + runnable.Run(weak_ptr.get(), CallbackForward(args)...); } }; -]] - -]] $$ for ARITY - #if !defined(_MSC_VER) template -- cgit v1.1