From c68d270b0cab7d4668f185c31482676eea7c0311 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 25 Feb 2016 10:08:07 +0100 Subject: [PATCH] functionTraits: Add reusable "functionTakesArgument" type Instead of doing the dispatch "function has enough arguments" + "argument is of correct type" for runAsync specifically, extract a reusable functionTakesArgument, which is either of type std::true_type or std::false_type. Change-Id: Iecfa867a0230d29fd96ae500423a5bdd1d475106 Reviewed-by: Tobias Hunger --- src/libs/utils/functiontraits.h | 50 +++++++++++++++++++++++++++++++++ src/libs/utils/runextensions.h | 21 ++------------ 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src/libs/utils/functiontraits.h b/src/libs/utils/functiontraits.h index 7b0d44d25ac..2544b525d91 100644 --- a/src/libs/utils/functiontraits.h +++ b/src/libs/utils/functiontraits.h @@ -29,6 +29,26 @@ namespace Utils { +/* + struct functionTraits + { + using ResultType; // Return type of Function + struct argument + { + using type; // type of Function argument at index (starting with 0) + } + } + + struct functionTakesArgument; + + Is derived from std::true_type if Function takes an argument of type ArgumentType at index. + Otherwise derived from std::false_type. +*/ + +//////////////////// +// functionTraits +//////////////////// + // for callables. defined below. template struct functionTraits; @@ -135,4 +155,34 @@ struct functionTraits : public functionTraits { }; +//////////////////// +// functionTakesArgument +//////////////////// +namespace Internal { + +template +struct functionTakesArgumentArityDispatch; + +template +struct functionTakesArgumentArityDispatch + : public std::false_type +{ +}; + +template +struct functionTakesArgumentArityDispatch + : public std::is_same::template argument::type> +{ +}; + +} // Internal + +template +struct functionTakesArgument : public Internal::functionTakesArgumentArityDispatch< + std::integral_constant::arity > index)>, + Function, index, T> +{ +}; + } // Utils diff --git a/src/libs/utils/runextensions.h b/src/libs/utils/runextensions.h index 565c98e4010..e08cc02bd6f 100644 --- a/src/libs/utils/runextensions.h +++ b/src/libs/utils/runextensions.h @@ -260,23 +260,6 @@ void runAsyncQFutureInterfaceDispatch(std::false_type, QFutureInterface(function), std::forward(args)...); } -// function that takes at least one argument which could be QFutureInterface -template -void runAsyncArityDispatch(std::true_type, QFutureInterface futureInterface, Function &&function, Args&&... args) -{ - runAsyncQFutureInterfaceDispatch(std::is_same&, - typename functionTraits::template argument<0>::type>(), - futureInterface, std::forward(function), std::forward(args)...); -} - -// function that does not take an argument, so it does not take a QFutureInterface -template -void runAsyncArityDispatch(std::false_type, QFutureInterface futureInterface, Function &&function, Args&&... args) -{ - runAsyncQFutureInterfaceDispatch(std::false_type(), - futureInterface, std::forward(function), std::forward(args)...); -} - // function, function pointer, or other callable object that is no member pointer template ::type> void runAsyncMemberDispatch(QFutureInterface futureInterface, Function &&function, Args&&... args) { - runAsyncArityDispatch(std::integral_constant::arity > 0)>(), - futureInterface, std::forward(function), std::forward(args)...); + runAsyncQFutureInterfaceDispatch(functionTakesArgument&>(), + futureInterface, std::forward(function), std::forward(args)...); } // Function = member function