5#ifndef QTBASE_QTTASKBUILDER_H
6#define QTBASE_QTTASKBUILDER_H
8#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
10#include <QtConcurrent/qtconcurrentstoredfunctioncall.h>
16namespace QtConcurrent {
18enum class FutureResult { Ignore };
20using InvokeResultType =
int;
22template <
class Task,
class ...Args>
27 QFuture<InvokeResultType> spawn();
29 void spawn(FutureResult);
31 template <
class ...ExtraArgs>
33 QTaskBuilder<Task, ExtraArgs...> withArguments(ExtraArgs &&...args);
36 QTaskBuilder<Task, Args...> &onThreadPool(QThreadPool &newThreadPool);
39 QTaskBuilder<Task, Args...> &withPriority(
int newPriority);
50template <
class Task,
class ...Args>
57 return TaskResolver<std::decay_t<Task>, std::decay_t<Args>...>::run(
58 std::move(taskWithArgs), startParameters);
64 (
new StoredFunctionCall<Task, Args...>(std::move(taskWithArgs)))
65 ->start(startParameters);
68 template <
class ...ExtraArgs>
72 static_assert(std::tuple_size_v<TaskWithArgs> == 1,
73 "This function cannot be invoked if "
74 "arguments have already been passed.");
76 static_assert(
sizeof...(ExtraArgs) >= 1,
77 "One or more arguments must be passed.");
80 return QTaskBuilder<Task, ExtraArgs...>(
82 std::get<0>(std::move(taskWithArgs)),
83 std::forward<ExtraArgs>(args)...
90 startParameters.threadPool = &newThreadPool;
97 startParameters.priority = newPriority;
107 const TaskStartParameters ¶meters, Task &&task, Args &&...arguments)
115 friend constexpr auto task(T &&t);
118 template <
class T,
class ...A>
124 TaskWithArgs taskWithArgs;
125 TaskStartParameters startParameters;
constexpr auto withArguments(ExtraArgs &&...args)
friend constexpr auto task(T &&t)
constexpr QTaskBuilder(Task &&task, Args &&...arguments)
constexpr QTaskBuilder(const TaskStartParameters ¶meters, Task &&task, Args &&...arguments)
constexpr auto & onThreadPool(QThreadPool &newThreadPool)
constexpr auto & withPriority(int newPriority)