diff --git a/src/corelib/thread/qfuture.h b/src/corelib/thread/qfuture.h index 44c5331261..101bdc7808 100644 --- a/src/corelib/thread/qfuture.h +++ b/src/corelib/thread/qfuture.h @@ -347,7 +347,7 @@ QFuture::template ResultType> QFuture::then(QtFuture::Launch policy, Function &&function) { QFutureInterface> promise(QFutureInterfaceBase::State::Pending); - QtPrivate::Continuation, T>::create( + QtPrivate::Continuation, ResultType, T>::create( std::forward(function), this, promise, policy); return promise.future(); } @@ -358,7 +358,7 @@ QFuture::template ResultType> QFuture::then(QTh Function &&function) { QFutureInterface> promise(QFutureInterfaceBase::State::Pending); - QtPrivate::Continuation, T>::create( + QtPrivate::Continuation, ResultType, T>::create( std::forward(function), this, promise, pool); return promise.future(); } @@ -370,7 +370,8 @@ template QFuture QFuture::onFailed(Function &&handler) { QFutureInterface promise(QFutureInterfaceBase::State::Pending); - QtPrivate::FailureHandler::create(std::forward(handler), this, promise); + QtPrivate::FailureHandler, T>::create(std::forward(handler), + this, promise); return promise.future(); } @@ -381,7 +382,8 @@ template QFuture QFuture::onCanceled(Function &&handler) { QFutureInterface promise(QFutureInterfaceBase::State::Pending); - QtPrivate::CanceledHandler::create(std::forward(handler), this, promise); + QtPrivate::CanceledHandler, T>::create(std::forward(handler), + this, promise); return promise.future(); } diff --git a/src/corelib/thread/qfuture_impl.h b/src/corelib/thread/qfuture_impl.h index 1a02cc9cf1..a837c3cefb 100644 --- a/src/corelib/thread/qfuture_impl.h +++ b/src/corelib/thread/qfuture_impl.h @@ -247,20 +247,23 @@ template class Continuation { public: - Continuation(Function &&func, const QFuture &f, + template + Continuation(F &&func, const QFuture &f, const QFutureInterface &p) - : promise(p), parentFuture(f), function(std::forward(func)) + : promise(p), parentFuture(f), function(std::forward(func)) { } virtual ~Continuation() = default; bool execute(); - static void create(Function &&func, QFuture *f, - QFutureInterface &p, QtFuture::Launch policy); + template + static void create(F &&func, QFuture *f, QFutureInterface &p, + QtFuture::Launch policy); - static void create(Function &&func, QFuture *f, - QFutureInterface &p, QThreadPool *pool); + template + static void create(F &&func, QFuture *f, QFutureInterface &p, + QThreadPool *pool); private: void fulfillPromiseWithResult(); @@ -285,9 +288,10 @@ template class SyncContinuation final : public Continuation { public: - SyncContinuation(Function &&func, const QFuture &f, + template + SyncContinuation(F &&func, const QFuture &f, const QFutureInterface &p) - : Continuation(std::forward(func), f, p) + : Continuation(std::forward(func), f, p) { } @@ -302,9 +306,10 @@ class AsyncContinuation final : public QRunnable, public Continuation { public: - AsyncContinuation(Function &&func, const QFuture &f, + template + AsyncContinuation(F &&func, const QFuture &f, const QFutureInterface &p, QThreadPool *pool = nullptr) - : Continuation(std::forward(func), f, p), + : Continuation(std::forward(func), f, p), threadPool(pool) { this->promise.setRunnable(this); @@ -334,12 +339,13 @@ template class FailureHandler { public: - static void create(Function &&function, QFuture *future, + template + static void create(F &&function, QFuture *future, const QFutureInterface &promise); - FailureHandler(Function &&func, const QFuture &f, - const QFutureInterface &p) - : promise(p), parentFuture(f), handler(std::forward(func)) + template + FailureHandler(F &&func, const QFuture &f, const QFutureInterface &p) + : promise(p), parentFuture(f), handler(std::forward(func)) { } @@ -438,7 +444,8 @@ bool Continuation::execute() } template -void Continuation::create(Function &&func, +template +void Continuation::create(F &&func, QFuture *f, QFutureInterface &p, QtFuture::Launch policy) @@ -461,10 +468,10 @@ void Continuation::create(Function &&fun Continuation *continuationJob = nullptr; if (launchAsync) { continuationJob = new AsyncContinuation( - std::forward(func), *f, p, pool); + std::forward(func), *f, p, pool); } else { continuationJob = new SyncContinuation( - std::forward(func), *f, p); + std::forward(func), *f, p); } p.setLaunchAsync(launchAsync); @@ -484,7 +491,8 @@ void Continuation::create(Function &&fun } template -void Continuation::create(Function &&func, +template +void Continuation::create(F &&func, QFuture *f, QFutureInterface &p, QThreadPool *pool) @@ -492,7 +500,7 @@ void Continuation::create(Function &&fun Q_ASSERT(f); auto continuationJob = new AsyncContinuation( - std::forward(func), *f, p, pool); + std::forward(func), *f, p, pool); p.setLaunchAsync(true); p.setThreadPool(pool); @@ -571,13 +579,14 @@ void fulfillPromise(QFutureInterface &promise, Function &&handler) #ifndef QT_NO_EXCEPTIONS template -void FailureHandler::create(Function &&function, QFuture *future, +template +void FailureHandler::create(F &&function, QFuture *future, const QFutureInterface &promise) { Q_ASSERT(future); - FailureHandler *failureHandler = new FailureHandler( - std::forward(function), *future, promise); + FailureHandler *failureHandler = + new FailureHandler(std::forward(function), *future, promise); auto failureContinuation = [failureHandler]() mutable { failureHandler->run(); @@ -654,13 +663,14 @@ template class CanceledHandler { public: - static QFuture create(Function &&handler, QFuture *future, + template + static QFuture create(F &&handler, QFuture *future, QFutureInterface promise) { Q_ASSERT(future); auto canceledContinuation = [parentFuture = *future, promise, - handler = std::move(handler)]() mutable { + handler = std::forward(handler)]() mutable { promise.reportStarted(); if (parentFuture.isCanceled()) {