4#ifndef QTCONCURRENT_STOREDFUNCTIONCALL_H
5#define QTCONCURRENT_STOREDFUNCTIONCALL_H
7#include <QtConcurrent/qtconcurrent_global.h>
9#ifndef QT_NO_CONCURRENT
10#include <QtConcurrent/qtconcurrentrunbase.h>
11#include <QtCore/qpromise.h>
22struct NonMemberFunctionResolver;
24template <
class Function,
class PromiseType,
class... Args>
25struct NonMemberFunctionResolver<Function, PromiseType, Args...>
27 using Type = std::tuple<std::decay_t<Function>, QPromise<PromiseType> &, std::decay_t<Args>...>;
28 static_assert(std::is_invocable_v<std::decay_t<Function>, QPromise<PromiseType> &, std::decay_t<Args>...>,
29 "It's not possible to invoke the function with passed arguments.");
30 static_assert(std::is_void_v<std::invoke_result_t<std::decay_t<Function>, QPromise<PromiseType> &, std::decay_t<Args>...>>,
31 "The function must return void type.");
33 static constexpr void invoke(std::decay_t<Function> function, QPromise<PromiseType> &promise,
34 std::decay_t<Args>... args)
36 std::invoke(function, promise, args...);
38 static Type initData(Function &&f, QPromise<PromiseType> &promise, Args &&...args)
40 return Type { std::forward<Function>(f), std::ref(promise), std::forward<Args>(args)... };
45struct MemberFunctionResolver;
47template <
typename Function,
typename PromiseType,
typename Arg,
typename ... Args>
48struct MemberFunctionResolver<Function, PromiseType, Arg, Args...>
50 using Type = std::tuple<std::decay_t<Function>, std::decay_t<Arg>, QPromise<PromiseType> &, std::decay_t<Args>...>;
51 static_assert(std::is_invocable_v<std::decay_t<Function>, std::decay_t<Arg>, QPromise<PromiseType> &, std::decay_t<Args>...>,
52 "It's not possible to invoke the function with passed arguments.");
53 static_assert(std::is_void_v<std::invoke_result_t<std::decay_t<Function>, std::decay_t<Arg>, QPromise<PromiseType> &, std::decay_t<Args>...>>,
54 "The function must return void type.");
56 static constexpr void invoke(std::decay_t<Function> function, std::decay_t<Arg> object,
57 QPromise<PromiseType> &promise, std::decay_t<Args>... args)
59 std::invoke(function, object, promise, args...);
61 static Type initData(Function &&f, QPromise<PromiseType> &promise, Arg &&fa, Args &&...args)
63 return Type { std::forward<Function>(f), std::forward<Arg>(fa), std::ref(promise), std::forward<Args>(args)... };
67template <
class IsMember,
class Function,
class PromiseType,
class... Args>
68struct FunctionResolverHelper;
82template <
class Function,
class PromiseType,
class... Args>
89template <
class Function,
class ...Args>
93 "It's not possible to invoke the function with passed arguments.");
98template <
class Function,
class ...Args>
99using InvokeResultType =
typename InvokeResult<Function, Args...>::Type;
101template <
class ...
Types>
104template <
class Function,
class ...Args>
136template <
class Function,
class PromiseType,
class ...Args>
140 using DataType =
typename Resolver::Type;
171struct NonPromiseTaskResolver;
173template <
typename Function,
typename ... Args>
174struct NonPromiseTaskResolver<Function, Args...>
176 using TaskWithArgs = DecayedTuple<Function, Args...>;
177 static auto run(TaskWithArgs &&args,
const TaskStartParameters &startParameters) {
178 return (
new StoredFunctionCall<Function, Args...>(std::move(args)))
179 ->start(startParameters);
184struct PromiseTaskResolver;
186template <
typename Function,
typename ... Args>
187struct PromiseTaskResolver<Function, Args...>
189 static_assert(QtPrivate::ArgResolver<Function>::IsPromise::value,
190 "The first argument of passed callable object isn't a QPromise<T> & type. "
191 "Did you intend to pass a callable which takes a QPromise<T> & type as a first argument? "
192 "Otherwise it's not possible to invoke the function with passed arguments.");
193 using TaskWithArgs = DecayedTuple<Function, Args...>;
194 static auto run(TaskWithArgs &&args,
const TaskStartParameters &startParameters) {
195 using PromiseType =
typename QtPrivate::ArgResolver<Function>::PromiseType;
196 return (
new StoredFunctionCallWithPromise<Function, PromiseType, Args...>(std::move(args)))
197 ->start(startParameters);
201template <
class IsDirectlyInvocable,
class Function,
class... Args>
202struct TaskResolverHelper;
216template <
class Function,
class... Args>
static Type initData(Function &&f, QPromise< PromiseType > &promise, Arg &&fa, Args &&...args)
static constexpr void invoke(std::decay_t< Function > function, std::decay_t< Arg > object, QPromise< PromiseType > &promise, std::decay_t< Args >... args)
static constexpr void invoke(std::decay_t< Function > function, QPromise< PromiseType > &promise, std::decay_t< Args >... args)
static Type initData(Function &&f, QPromise< PromiseType > &promise, Args &&...args)
static auto run(TaskWithArgs &&args, const TaskStartParameters &startParameters)
static auto run(TaskWithArgs &&args, const TaskStartParameters &startParameters)
StoredFunctionCallWithPromise(Function &&f, Args &&...args)
void runFunctor() override