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