26 static_assert (
std::is_move_constructible_v<T>
27 ||
std::is_same_v<T,
void>,
28 "A move-constructible type or type void is required");
31 Q_DISABLE_COPY(QPromise)
32 QPromise(QPromise<T> &&other) =
default;
34 QPromise(QFutureInterface<T> &&other)
noexcept : d(std::move(other)) {}
35 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QPromise)
40 if (d.d && !(d.loadState() & QFutureInterfaceBase::State::Finished)) {
44 d.cleanContinuation();
48 QFuture<T> future()
const {
return d.future(); }
49 template<
typename...Args, std::enable_if_t<std::is_constructible_v<T, Args...>,
bool> =
true>
50 bool emplaceResultAt(
int index, Args&&...args)
52 return d.reportAndEmplaceResult(index, std::forward<Args>(args)...);
54 template<
typename...Args, std::enable_if_t<std::is_constructible_v<T, Args...>,
bool> =
true>
55 bool emplaceResult(Args&&...args)
57 return d.reportAndEmplaceResult(-1, std::forward<Args>(args)...);
59 template<
typename U = T,
typename = QtPrivate::EnableIfSameOrConvertible<U, T>>
60 bool addResult(U &&result,
int index = -1)
62 return d.reportAndEmplaceResult(index, std::forward<U>(result));
64 bool addResults(
const QList<T> &result)
65 {
return d.reportResults(result); }
66#ifndef QT_NO_EXCEPTIONS
67 void setException(
const QException &e) { d.reportException(e); }
68#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
69 void setException(std::exception_ptr e) { d.reportException(e); }
71 void setException(
const std::exception_ptr &e) { d.reportException(e); }
74 void start() { d.reportStarted(); }
75 void finish() { d.reportFinished(); }
77 void suspendIfRequested() { d.suspendIfRequested(); }
79 bool isCanceled()
const {
return d.isCanceled(); }
82 void setProgressRange(
int minimum,
int maximum) { d.setProgressRange(minimum, maximum); }
83 void setProgressValue(
int progressValue) { d.setProgressValue(progressValue); }
84 void setProgressValueAndText(
int progressValue,
const QString &progressText)
86 d.setProgressValueAndText(progressValue, progressText);
89 void swap(QPromise<T> &other)
noexcept
95 bool addResult(
const T &result,
int index = -1) { }
96 bool addResult(T &&result,
int index = -1) { }
99 mutable QFutureInterface<T> d;