4#ifndef QTBASE_QTTASKBUILDER_H
5#define QTBASE_QTTASKBUILDER_H
7#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
9#include <QtConcurrent/qtconcurrentstoredfunctioncall.h>
15namespace QtConcurrent {
17enum class FutureResult { Ignore };
19using InvokeResultType =
int;
21template <
class Task,
class ...Args>
26 QFuture<InvokeResultType> spawn();
28 void spawn(FutureResult);
30 template <
class ...ExtraArgs>
32 QTaskBuilder<Task, ExtraArgs...> withArguments(ExtraArgs &&...args);
35 QTaskBuilder<Task, Args...> &onThreadPool(QThreadPool &newThreadPool);
38 QTaskBuilder<Task, Args...> &withPriority(
int newPriority);
49template <
class Task,
class ...Args>
56 return TaskResolver<std::decay_t<Task>, std::decay_t<Args>...>::run(
57 std::move(taskWithArgs), startParameters);
63 (
new StoredFunctionCall<Task, Args...>(std::move(taskWithArgs)))
64 ->start(startParameters);
67 template <
class ...ExtraArgs>
71 static_assert(std::tuple_size_v<TaskWithArgs> == 1,
72 "This function cannot be invoked if "
73 "arguments have already been passed.");
75 static_assert(
sizeof...(ExtraArgs) >= 1,
76 "One or more arguments must be passed.");
79 return QTaskBuilder<Task, ExtraArgs...>(
81 std::get<0>(std::move(taskWithArgs)),
82 std::forward<ExtraArgs>(args)...
89 startParameters.threadPool = &newThreadPool;
96 startParameters.priority = newPriority;
106 const TaskStartParameters ¶meters, Task &&task, Args &&...arguments)
114 friend constexpr auto task(T &&t);
117 template <
class T,
class ...A>
123 TaskWithArgs taskWithArgs;
124 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)