diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp index 37388baf037..de0ad9d61a5 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp @@ -319,10 +319,10 @@ QFuture ModelManagerInterface::refreshSourceFiles(const QStringList &sourc if (sourceFiles.isEmpty()) return QFuture(); - QFuture result = Utils::runAsync(&ModelManagerInterface::parse, - workingCopyInternal(), sourceFiles, - this, Dialect(Dialect::Qml), - emitDocumentOnDiskChanged); + QFuture result = Utils::runAsync(&ModelManagerInterface::parse, + workingCopyInternal(), sourceFiles, + this, Dialect(Dialect::Qml), + emitDocumentOnDiskChanged); cleanupFutures(); m_futures.append(result); @@ -348,9 +348,9 @@ QFuture ModelManagerInterface::refreshSourceFiles(const QStringList &sourc void ModelManagerInterface::fileChangedOnDisk(const QString &path) { - Utils::runAsync(&ModelManagerInterface::parse, - workingCopyInternal(), QStringList() << path, - this, Dialect(Dialect::AnyLanguage), true); + Utils::runAsync(&ModelManagerInterface::parse, + workingCopyInternal(), QStringList() << path, + this, Dialect(Dialect::AnyLanguage), true); } void ModelManagerInterface::removeFiles(const QStringList &files) @@ -1096,9 +1096,9 @@ void ModelManagerInterface::maybeScan(const PathsAndLanguages &importPaths) } if (pathToScan.length() > 1) { - QFuture result = Utils::runAsync(&ModelManagerInterface::importScan, - workingCopyInternal(), pathToScan, - this, true, true); + QFuture result = Utils::runAsync(&ModelManagerInterface::importScan, + workingCopyInternal(), pathToScan, + this, true, true); cleanupFutures(); m_futures.append(result); @@ -1243,7 +1243,7 @@ void ModelManagerInterface::startCppQmlTypeUpdate() if (!cppModelManager) return; - m_cppQmlTypesUpdater = Utils::runAsync(&ModelManagerInterface::updateCppQmlTypes, + m_cppQmlTypesUpdater = Utils::runAsync(&ModelManagerInterface::updateCppQmlTypes, this, cppModelManager->snapshot(), m_queuedCppDocuments); m_queuedCppDocuments.clear(); } diff --git a/src/libs/utils/runextensions.h b/src/libs/utils/runextensions.h index 7ce245e2398..4b9c3b40738 100644 --- a/src/libs/utils/runextensions.h +++ b/src/libs/utils/runextensions.h @@ -435,6 +435,138 @@ QT_END_NAMESPACE namespace Utils { namespace Internal { +/* + resultType::type + + Returns the type of results that would be reported by a callable of type F + when called through the runAsync methods. I.e. the ResultType in + + void f(QFutureInterface &fi, ...) + ResultType f(...) + + Returns void if F is not callable, and if F is a callable that does not take + a QFutureInterface& as its first parameter and returns void. +*/ + +template +struct hasCallOperator +{ + using yes = char; + using no = struct { char foo[2]; }; + + template + static yes test(decltype(&C::operator())); + + template + static no test(...); + + static const bool value = (sizeof(test(0)) == sizeof(yes)); +}; + +template +struct resultType; + +template +struct resultTypeWithArgument; + +template +struct resultTypeTakesArguments; + +template +struct resultTypeIsMemberFunction; + +template +struct resultTypeIsFunctionLike; + +template +struct resultTypeHasCallOperator; + +template +struct resultTypeWithArgument&> +{ + using type = ResultType; +}; + +template +struct resultTypeWithArgument +{ + using type = typename functionTraits::ResultType; +}; + +template +struct resultTypeTakesArguments + : public resultTypeWithArgument::template argument::type> +{ +}; + +template +struct resultTypeTakesArguments +{ + using type = typename functionTraits::ResultType; +}; + +template +struct resultTypeIsFunctionLike + : public resultTypeTakesArguments::arity > 0)> +{ +}; + +template +struct resultTypeIsMemberFunction + : public resultTypeTakesArguments::arity > 1)> +{ +}; + +template +struct resultTypeIsMemberFunction +{ + using type = void; +}; + +template +struct resultTypeIsFunctionLike + : public resultTypeIsMemberFunction::value> +{ +}; + +template +struct resultTypeHasCallOperator + : public resultTypeIsFunctionLike::type>::type>::value> +{ +}; + +template +struct resultTypeHasCallOperator + : public resultTypeTakesArguments::arity > 1)> +{ +}; + +template +struct resultType + : public resultTypeHasCallOperator::value> +{ +}; + +template +struct resultType : public resultType +{ +}; + +template +struct resultType : public resultType +{ +}; + +template +struct resultType : public resultType +{ +}; + +/* + Callable object that wraps a member function pointer with the object it + will be called on. +*/ + template class MemberCallable; @@ -478,6 +610,10 @@ private: Obj *m_obj; }; +/* + Helper functions for runAsync that run in the started thread. +*/ + // void function that does not take QFutureInterface template void runAsyncReturnVoidDispatch(std::true_type, QFutureInterface futureInterface, Function &&function, Args&&... args) @@ -557,6 +693,11 @@ void runAsyncImpl(QFutureInterface futureInterface, Function &&funct std::forward(args)...); } +/* + AsyncJob is a QRunnable that wraps a function with the + arguments that are passed to it when it is run in a thread. +*/ + // can be replaced with std::(make_)index_sequence with C++14 template struct indexSequence { }; @@ -671,9 +812,10 @@ private: \sa QThreadPool \sa QThread::Priority */ -template -QFuture runAsync(QThreadPool *pool, QThread::Priority priority, - Function &&function, Args&&... args) +template ::type> +QFuture +runAsync(QThreadPool *pool, QThread::Priority priority, Function &&function, Args&&... args) { auto job = new Internal::AsyncJob (std::forward(function), std::forward(args)...); @@ -696,11 +838,13 @@ QFuture runAsync(QThreadPool *pool, QThread::Priority priority, \sa runAsync(QThreadPool*,QThread::Priority,Function&&,Args&&...) \sa QThread::Priority */ -template -QFuture runAsync(QThread::Priority priority, Function &&function, Args&&... args) +template ::type> +QFuture +runAsync(QThread::Priority priority, Function &&function, Args&&... args) { - return runAsync(static_cast(nullptr), priority, - std::forward(function), std::forward(args)...); + return runAsync(static_cast(nullptr), priority, + std::forward(function), std::forward(args)...); } /*! @@ -708,16 +852,18 @@ QFuture runAsync(QThread::Priority priority, Function &&function, Ar \sa runAsync(QThreadPool*,QThread::Priority,Function&&,Args&&...) \sa QThread::Priority */ -template ::type, QThreadPool>::value && !std::is_same::type, QThread::Priority>::value - >::type> -QFuture runAsync(Function &&function, Args&&... args) + >::type, + typename ResultType = typename Internal::resultType::type> +QFuture +runAsync(Function &&function, Args&&... args) { - return runAsync(static_cast(nullptr), - QThread::InheritPriority, std::forward(function), - std::forward(args)...); + return runAsync(static_cast(nullptr), + QThread::InheritPriority, std::forward(function), + std::forward(args)...); } /*! @@ -725,15 +871,16 @@ QFuture runAsync(Function &&function, Args&&... args) \sa runAsync(QThreadPool*,QThread::Priority,Function&&,Args&&...) \sa QThread::Priority */ -template ::type, QThread::Priority>::value - >::type> -QFuture runAsync(QThreadPool *pool, - Function &&function, Args&&... args) + >::type, + typename ResultType = typename Internal::resultType::type> +QFuture +runAsync(QThreadPool *pool, Function &&function, Args&&... args) { - return runAsync(pool, QThread::InheritPriority, std::forward(function), - std::forward(args)...); + return runAsync(pool, QThread::InheritPriority, std::forward(function), + std::forward(args)...); } } // Utils diff --git a/src/libs/utils/shellcommand.cpp b/src/libs/utils/shellcommand.cpp index e0394cc4b03..15394d938e5 100644 --- a/src/libs/utils/shellcommand.cpp +++ b/src/libs/utils/shellcommand.cpp @@ -222,7 +222,7 @@ void ShellCommand::execute() if (d->m_jobs.empty()) return; - QFuture task = Utils::runAsync(&ShellCommand::run, this); + QFuture task = Utils::runAsync(&ShellCommand::run, this); d->m_watcher.setFuture(task); addTask(task); } diff --git a/src/plugins/autotest/testcodeparser.cpp b/src/plugins/autotest/testcodeparser.cpp index e8e379ed1f0..1c39416919a 100644 --- a/src/plugins/autotest/testcodeparser.cpp +++ b/src/plugins/autotest/testcodeparser.cpp @@ -738,7 +738,7 @@ void TestCodeParser::scanForTests(const QStringList &fileList) } QFuture future - = Utils::runAsync(&performParse, list, referencingFiles); + = Utils::runAsync(&performParse, list, referencingFiles); m_futureWatcher.setFuture(future); if (list.size() > 5) { Core::ProgressManager::addTask(future, tr("Scanning for Tests"), diff --git a/src/plugins/autotest/testrunner.cpp b/src/plugins/autotest/testrunner.cpp index daab98068bc..2bece16b65c 100644 --- a/src/plugins/autotest/testrunner.cpp +++ b/src/plugins/autotest/testrunner.cpp @@ -285,8 +285,8 @@ void TestRunner::runTests() const QSharedPointer settings = AutotestPlugin::instance()->settings(); const QString &metricsOption = TestSettings::metricsTypeToOption(settings->metrics); - QFuture future = Utils::runAsync(&performTestRun, m_selectedTests, - settings->timeout, metricsOption); + QFuture future = Utils::runAsync(&performTestRun, m_selectedTests, + settings->timeout, metricsOption); m_futureWatcher.setFuture(future); Core::ProgressManager::addTask(future, tr("Running Tests"), Autotest::Constants::TASK_INDEX); } diff --git a/src/plugins/coreplugin/locator/locatorfiltertest.cpp b/src/plugins/coreplugin/locator/locatorfiltertest.cpp index a2c1844f9e8..a286e55e980 100644 --- a/src/plugins/coreplugin/locator/locatorfiltertest.cpp +++ b/src/plugins/coreplugin/locator/locatorfiltertest.cpp @@ -45,9 +45,8 @@ QList BasicLocatorFilterTest::matchesFor(const QString &sear doBeforeLocatorRun(); const QList filters = QList() << m_filter; m_filter->prepareSearch(searchText); - QFuture locatorSearch = Utils::runAsync(&Internal::runSearch, - filters, - searchText); + QFuture locatorSearch = Utils::runAsync(&Internal::runSearch, filters, + searchText); locatorSearch.waitForFinished(); doAfterLocatorRun(); return locatorSearch.results(); diff --git a/src/plugins/coreplugin/locator/locatorwidget.cpp b/src/plugins/coreplugin/locator/locatorwidget.cpp index d5462459e56..4dd47d3bea2 100644 --- a/src/plugins/coreplugin/locator/locatorwidget.cpp +++ b/src/plugins/coreplugin/locator/locatorwidget.cpp @@ -520,8 +520,7 @@ void LocatorWidget::updateCompletionList(const QString &text) foreach (ILocatorFilter *filter, filters) filter->prepareSearch(searchText); - QFuture future = Utils::runAsync(&runSearch, filters, - searchText); + QFuture future = Utils::runAsync(&runSearch, filters, searchText); m_entriesWatcher->setFuture(future); } diff --git a/src/plugins/git/gitgrep.cpp b/src/plugins/git/gitgrep.cpp index a00fa401b54..57ce4afb22d 100644 --- a/src/plugins/git/gitgrep.cpp +++ b/src/plugins/git/gitgrep.cpp @@ -235,7 +235,7 @@ void GitGrep::writeSettings(QSettings *settings) const QFuture GitGrep::executeSearch( const TextEditor::FileFindParameters ¶meters) { - return Utils::runAsync(GitGrepRunner::run, parameters); + return Utils::runAsync(GitGrepRunner::run, parameters); } } // Internal diff --git a/src/plugins/qmakeprojectmanager/qmakenodes.cpp b/src/plugins/qmakeprojectmanager/qmakenodes.cpp index faed46c8162..7c9e0dcb589 100644 --- a/src/plugins/qmakeprojectmanager/qmakenodes.cpp +++ b/src/plugins/qmakeprojectmanager/qmakenodes.cpp @@ -1806,10 +1806,10 @@ void QmakeProFileNode::asyncUpdate() m_readerExact->setExact(false); m_parseFutureWatcher.waitForFinished(); EvalInput input = evalInput(); - QFuture future = Utils::runAsync(ProjectExplorerPlugin::sharedThreadPool(), - QThread::LowestPriority, - &QmakeProFileNode::asyncEvaluate, - this, input); + QFuture future = Utils::runAsync(ProjectExplorerPlugin::sharedThreadPool(), + QThread::LowestPriority, + &QmakeProFileNode::asyncEvaluate, + this, input); m_parseFutureWatcher.setFuture(future); } diff --git a/src/plugins/qmljseditor/qmljsfindreferences.cpp b/src/plugins/qmljseditor/qmljsfindreferences.cpp index a5c994265fb..6c7ff6eb13f 100644 --- a/src/plugins/qmljseditor/qmljsfindreferences.cpp +++ b/src/plugins/qmljseditor/qmljsfindreferences.cpp @@ -891,10 +891,8 @@ void FindReferences::findUsages(const QString &fileName, quint32 offset) { ModelManagerInterface *modelManager = ModelManagerInterface::instance(); - QFuture result = Utils::runAsync( - &find_helper, modelManager->workingCopy(), - modelManager->snapshot(), fileName, offset, - QString()); + QFuture result = Utils::runAsync(&find_helper, modelManager->workingCopy(), + modelManager->snapshot(), fileName, offset, QString()); m_watcher.setFuture(result); } @@ -908,10 +906,8 @@ void FindReferences::renameUsages(const QString &fileName, quint32 offset, if (newName.isNull()) newName = QLatin1String(""); - QFuture result = Utils::runAsync( - &find_helper, modelManager->workingCopy(), - modelManager->snapshot(), fileName, offset, - newName); + QFuture result = Utils::runAsync(&find_helper, modelManager->workingCopy(), + modelManager->snapshot(), fileName, offset, newName); m_watcher.setFuture(result); } diff --git a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp index 493f2efeb23..0f2dea0442d 100644 --- a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp +++ b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp @@ -545,8 +545,8 @@ void SemanticHighlighter::rerun(const QmlJSTools::SemanticInfo &semanticInfo) m_watcher.cancel(); m_startRevision = m_document->document()->revision(); - m_watcher.setFuture(Utils::runAsync(QThread::LowestPriority, - &SemanticHighlighter::run, this, semanticInfo)); + m_watcher.setFuture(Utils::runAsync(QThread::LowestPriority, + &SemanticHighlighter::run, this, semanticInfo)); } void SemanticHighlighter::cancel() diff --git a/src/plugins/qmljseditor/qmltaskmanager.cpp b/src/plugins/qmljseditor/qmltaskmanager.cpp index 252dbf43910..f0e28ad6d3a 100644 --- a/src/plugins/qmljseditor/qmltaskmanager.cpp +++ b/src/plugins/qmljseditor/qmltaskmanager.cpp @@ -152,7 +152,7 @@ void QmlTaskManager::updateMessagesNow(bool updateSemantic) // process them QFuture future = - Utils::runAsync( + Utils::runAsync( &collectMessages, modelManager->newestSnapshot(), modelManager->projectInfos(), modelManager->defaultVContext(Dialect::AnyLanguage), updateSemantic); m_messageCollector.setFuture(future); diff --git a/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp b/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp index 84ec4681400..154e8448049 100644 --- a/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp +++ b/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp @@ -347,7 +347,7 @@ void QmlProfilerModelManager::save(const QString &filename) connect(writer, &QObject::destroyed, this, &QmlProfilerModelManager::saveFinished, Qt::QueuedConnection); - QFuture result = Utils::runAsync([file, writer] (QFutureInterface &future) { + QFuture result = Utils::runAsync([file, writer] (QFutureInterface &future) { writer->setFuture(&future); writer->save(file); delete writer; @@ -387,7 +387,7 @@ void QmlProfilerModelManager::load(const QString &filename) acquiringDone(); }, Qt::QueuedConnection); - QFuture result = Utils::runAsync([file, reader] (QFutureInterface &future) { + QFuture result = Utils::runAsync([file, reader] (QFutureInterface &future) { reader->setFuture(&future); reader->load(file); file->close(); diff --git a/src/plugins/texteditor/generichighlighter/manager.cpp b/src/plugins/texteditor/generichighlighter/manager.cpp index 6286e2927a8..2ab4e58e2b0 100644 --- a/src/plugins/texteditor/generichighlighter/manager.cpp +++ b/src/plugins/texteditor/generichighlighter/manager.cpp @@ -322,7 +322,7 @@ void Manager::registerHighlightingFiles() if (!m_registeringWatcher.isRunning()) { clear(); - QFuture future = Utils::runAsync(ManagerProcessor()); + QFuture future = Utils::runAsync(ManagerProcessor()); m_registeringWatcher.setFuture(future); } else { m_hasQueuedRegistration = true; diff --git a/src/plugins/vcsbase/cleandialog.cpp b/src/plugins/vcsbase/cleandialog.cpp index af16ece7ddc..7f424f0e6ce 100644 --- a/src/plugins/vcsbase/cleandialog.cpp +++ b/src/plugins/vcsbase/cleandialog.cpp @@ -250,8 +250,8 @@ bool CleanDialog::promptToDelete() return false; // Remove in background - QFuture task = Utils::runAsync(Internal::runCleanFiles, d->m_workingDirectory, - selectedFiles, Internal::handleError); + QFuture task = Utils::runAsync(Internal::runCleanFiles, d->m_workingDirectory, + selectedFiles, Internal::handleError); const QString taskName = tr("Cleaning \"%1\""). arg(QDir::toNativeSeparators(d->m_workingDirectory)); diff --git a/tests/auto/runextensions/tst_runextensions.cpp b/tests/auto/runextensions/tst_runextensions.cpp index 13f8aabca1f..eb3deff7faf 100644 --- a/tests/auto/runextensions/tst_runextensions.cpp +++ b/tests/auto/runextensions/tst_runextensions.cpp @@ -185,40 +185,40 @@ public: void tst_RunExtensions::runAsync() { // free function pointer - QCOMPARE(Utils::runAsync(&report3).results(), + QCOMPARE(Utils::runAsync(&report3).results(), QList({0, 2, 1})); - QCOMPARE(Utils::runAsync(report3).results(), + QCOMPARE(Utils::runAsync(report3).results(), QList({0, 2, 1})); - QCOMPARE(Utils::runAsync(reportN, 4).results(), + QCOMPARE(Utils::runAsync(reportN, 4).results(), QList({0, 0, 0, 0})); - QCOMPARE(Utils::runAsync(reportN, 2).results(), + QCOMPARE(Utils::runAsync(reportN, 2).results(), QList({0, 0})); QString s = QLatin1String("string"); const QString &crs = QLatin1String("cr string"); const QString cs = QLatin1String("c string"); - QCOMPARE(Utils::runAsync(reportString1, s).results(), + QCOMPARE(Utils::runAsync(reportString1, s).results(), QList({s})); - QCOMPARE(Utils::runAsync(reportString1, crs).results(), + QCOMPARE(Utils::runAsync(reportString1, crs).results(), QList({crs})); - QCOMPARE(Utils::runAsync(reportString1, cs).results(), + QCOMPARE(Utils::runAsync(reportString1, cs).results(), QList({cs})); - QCOMPARE(Utils::runAsync(reportString1, QString(QLatin1String("rvalue"))).results(), + QCOMPARE(Utils::runAsync(reportString1, QString(QLatin1String("rvalue"))).results(), QList({QString(QLatin1String("rvalue"))})); - QCOMPARE(Utils::runAsync(reportString2, s).results(), + QCOMPARE(Utils::runAsync(reportString2, s).results(), QList({s})); - QCOMPARE(Utils::runAsync(reportString2, crs).results(), + QCOMPARE(Utils::runAsync(reportString2, crs).results(), QList({crs})); - QCOMPARE(Utils::runAsync(reportString2, cs).results(), + QCOMPARE(Utils::runAsync(reportString2, cs).results(), QList({cs})); - QCOMPARE(Utils::runAsync(reportString2, QString(QLatin1String("rvalue"))).results(), + QCOMPARE(Utils::runAsync(reportString2, QString(QLatin1String("rvalue"))).results(), QList({QString(QLatin1String("rvalue"))})); // lambda - QCOMPARE(Utils::runAsync([](QFutureInterface &fi, int n) { + QCOMPARE(Utils::runAsync([](QFutureInterface &fi, int n) { fi.reportResults(QVector(n, 0)); }, 3).results(), QList({0, 0, 0})); @@ -227,46 +227,46 @@ void tst_RunExtensions::runAsync() const std::function&,int)> fun = [](QFutureInterface &fi, int n) { fi.reportResults(QVector(n, 0)); }; - QCOMPARE(Utils::runAsync(fun, 2).results(), + QCOMPARE(Utils::runAsync(fun, 2).results(), QList({0, 0})); // operator() - QCOMPARE(Utils::runAsync(Callable(), 3).results(), + QCOMPARE(Utils::runAsync(Callable(), 3).results(), QList({0, 0, 0})); const Callable c{}; - QCOMPARE(Utils::runAsync(c, 2).results(), + QCOMPARE(Utils::runAsync(c, 2).results(), QList({0, 0})); // static member functions - QCOMPARE(Utils::runAsync(&MyObject::staticMember0).results(), + QCOMPARE(Utils::runAsync(&MyObject::staticMember0).results(), QList({0, 2, 1})); - QCOMPARE(Utils::runAsync(&MyObject::staticMember1, 2).results(), + QCOMPARE(Utils::runAsync(&MyObject::staticMember1, 2).results(), QList({0, 0})); // member functions const MyObject obj{}; - QCOMPARE(Utils::runAsync(&MyObject::member0, &obj).results(), + QCOMPARE(Utils::runAsync(&MyObject::member0, &obj).results(), QList({0, 2, 1})); - QCOMPARE(Utils::runAsync(&MyObject::member1, &obj, 4).results(), + QCOMPARE(Utils::runAsync(&MyObject::member1, &obj, 4).results(), QList({0, 0, 0, 0})); - QCOMPARE(Utils::runAsync(&MyObject::memberString1, &obj, s).results(), + QCOMPARE(Utils::runAsync(&MyObject::memberString1, &obj, s).results(), QList({s})); - QCOMPARE(Utils::runAsync(&MyObject::memberString1, &obj, crs).results(), + QCOMPARE(Utils::runAsync(&MyObject::memberString1, &obj, crs).results(), QList({crs})); - QCOMPARE(Utils::runAsync(&MyObject::memberString1, &obj, cs).results(), + QCOMPARE(Utils::runAsync(&MyObject::memberString1, &obj, cs).results(), QList({cs})); - QCOMPARE(Utils::runAsync(&MyObject::memberString1, &obj, QString(QLatin1String("rvalue"))).results(), + QCOMPARE(Utils::runAsync(&MyObject::memberString1, &obj, QString(QLatin1String("rvalue"))).results(), QList({QString(QLatin1String("rvalue"))})); - QCOMPARE(Utils::runAsync(&MyObject::memberString2, &obj, s).results(), + QCOMPARE(Utils::runAsync(&MyObject::memberString2, &obj, s).results(), QList({s})); - QCOMPARE(Utils::runAsync(&MyObject::memberString2, &obj, crs).results(), + QCOMPARE(Utils::runAsync(&MyObject::memberString2, &obj, crs).results(), QList({crs})); - QCOMPARE(Utils::runAsync(&MyObject::memberString2, &obj, cs).results(), + QCOMPARE(Utils::runAsync(&MyObject::memberString2, &obj, cs).results(), QList({cs})); - QCOMPARE(Utils::runAsync(&MyObject::memberString2, &obj, QString(QLatin1String("rvalue"))).results(), + QCOMPARE(Utils::runAsync(&MyObject::memberString2, &obj, QString(QLatin1String("rvalue"))).results(), QList({QString(QLatin1String("rvalue"))})); MyObject nonConstObj{}; - QCOMPARE(Utils::runAsync(&MyObject::nonConstMember, &nonConstObj).results(), + QCOMPARE(Utils::runAsync(&MyObject::nonConstMember, &nonConstObj).results(), QList({0, 2, 1})); } @@ -274,40 +274,40 @@ void tst_RunExtensions::runInThreadPool() { QScopedPointer pool(new QThreadPool); // free function pointer - QCOMPARE(Utils::runAsync(pool.data(), &report3).results(), + QCOMPARE(Utils::runAsync(pool.data(), &report3).results(), QList({0, 2, 1})); - QCOMPARE(Utils::runAsync(pool.data(), report3).results(), + QCOMPARE(Utils::runAsync(pool.data(), report3).results(), QList({0, 2, 1})); - QCOMPARE(Utils::runAsync(pool.data(), reportN, 4).results(), + QCOMPARE(Utils::runAsync(pool.data(), reportN, 4).results(), QList({0, 0, 0, 0})); - QCOMPARE(Utils::runAsync(pool.data(), reportN, 2).results(), + QCOMPARE(Utils::runAsync(pool.data(), reportN, 2).results(), QList({0, 0})); QString s = QLatin1String("string"); const QString &crs = QLatin1String("cr string"); const QString cs = QLatin1String("c string"); - QCOMPARE(Utils::runAsync(pool.data(), reportString1, s).results(), + QCOMPARE(Utils::runAsync(pool.data(), reportString1, s).results(), QList({s})); - QCOMPARE(Utils::runAsync(pool.data(), reportString1, crs).results(), + QCOMPARE(Utils::runAsync(pool.data(), reportString1, crs).results(), QList({crs})); - QCOMPARE(Utils::runAsync(pool.data(), reportString1, cs).results(), + QCOMPARE(Utils::runAsync(pool.data(), reportString1, cs).results(), QList({cs})); - QCOMPARE(Utils::runAsync(pool.data(), reportString1, QString(QLatin1String("rvalue"))).results(), + QCOMPARE(Utils::runAsync(pool.data(), reportString1, QString(QLatin1String("rvalue"))).results(), QList({QString(QLatin1String("rvalue"))})); - QCOMPARE(Utils::runAsync(pool.data(), reportString2, s).results(), + QCOMPARE(Utils::runAsync(pool.data(), reportString2, s).results(), QList({s})); - QCOMPARE(Utils::runAsync(pool.data(), reportString2, crs).results(), + QCOMPARE(Utils::runAsync(pool.data(), reportString2, crs).results(), QList({crs})); - QCOMPARE(Utils::runAsync(pool.data(), reportString2, cs).results(), + QCOMPARE(Utils::runAsync(pool.data(), reportString2, cs).results(), QList({cs})); - QCOMPARE(Utils::runAsync(pool.data(), reportString2, QString(QLatin1String("rvalue"))).results(), + QCOMPARE(Utils::runAsync(pool.data(), reportString2, QString(QLatin1String("rvalue"))).results(), QList({QString(QLatin1String("rvalue"))})); // lambda - QCOMPARE(Utils::runAsync(pool.data(), [](QFutureInterface &fi, int n) { + QCOMPARE(Utils::runAsync(pool.data(), [](QFutureInterface &fi, int n) { fi.reportResults(QVector(n, 0)); }, 3).results(), QList({0, 0, 0})); @@ -316,43 +316,43 @@ void tst_RunExtensions::runInThreadPool() const std::function&,int)> fun = [](QFutureInterface &fi, int n) { fi.reportResults(QVector(n, 0)); }; - QCOMPARE(Utils::runAsync(pool.data(), fun, 2).results(), + QCOMPARE(Utils::runAsync(pool.data(), fun, 2).results(), QList({0, 0})); // operator() - QCOMPARE(Utils::runAsync(pool.data(), Callable(), 3).results(), + QCOMPARE(Utils::runAsync(pool.data(), Callable(), 3).results(), QList({0, 0, 0})); const Callable c{}; - QCOMPARE(Utils::runAsync(pool.data(), c, 2).results(), + QCOMPARE(Utils::runAsync(pool.data(), c, 2).results(), QList({0, 0})); // static member functions - QCOMPARE(Utils::runAsync(pool.data(), &MyObject::staticMember0).results(), + QCOMPARE(Utils::runAsync(pool.data(), &MyObject::staticMember0).results(), QList({0, 2, 1})); - QCOMPARE(Utils::runAsync(pool.data(), &MyObject::staticMember1, 2).results(), + QCOMPARE(Utils::runAsync(pool.data(), &MyObject::staticMember1, 2).results(), QList({0, 0})); // member functions const MyObject obj{}; - QCOMPARE(Utils::runAsync(pool.data(), &MyObject::member0, &obj).results(), + QCOMPARE(Utils::runAsync(pool.data(), &MyObject::member0, &obj).results(), QList({0, 2, 1})); - QCOMPARE(Utils::runAsync(pool.data(), &MyObject::member1, &obj, 4).results(), + QCOMPARE(Utils::runAsync(pool.data(), &MyObject::member1, &obj, 4).results(), QList({0, 0, 0, 0})); - QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString1, &obj, s).results(), + QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString1, &obj, s).results(), QList({s})); - QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString1, &obj, crs).results(), + QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString1, &obj, crs).results(), QList({crs})); - QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString1, &obj, cs).results(), + QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString1, &obj, cs).results(), QList({cs})); - QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString1, &obj, QString(QLatin1String("rvalue"))).results(), + QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString1, &obj, QString(QLatin1String("rvalue"))).results(), QList({QString(QLatin1String("rvalue"))})); - QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString2, &obj, s).results(), + QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString2, &obj, s).results(), QList({s})); - QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString2, &obj, crs).results(), + QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString2, &obj, crs).results(), QList({crs})); - QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString2, &obj, cs).results(), + QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString2, &obj, cs).results(), QList({cs})); - QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString2, &obj, QString(QLatin1String("rvalue"))).results(), + QCOMPARE(Utils::runAsync(pool.data(), &MyObject::memberString2, &obj, QString(QLatin1String("rvalue"))).results(), QList({QString(QLatin1String("rvalue"))})); } @@ -379,7 +379,7 @@ public: void tst_RunExtensions::moveOnlyType() { - QCOMPARE(Utils::runAsync(MoveOnlyCallable(), MoveOnlyType()).results(), + QCOMPARE(Utils::runAsync(MoveOnlyCallable(), MoveOnlyType()).results(), QList({1})); } @@ -389,11 +389,11 @@ void tst_RunExtensions::threadPriority() { QScopedPointer pool(new QThreadPool); // with pool - QCOMPARE(Utils::runAsync(pool.data(), QThread::LowestPriority, &report3).results(), + QCOMPARE(Utils::runAsync(pool.data(), QThread::LowestPriority, &report3).results(), QList({0, 2, 1})); // without pool - QCOMPARE(Utils::runAsync(QThread::LowestPriority, report3).results(), + QCOMPARE(Utils::runAsync(QThread::LowestPriority, report3).results(), QList({0, 2, 1})); } @@ -401,37 +401,37 @@ void tst_RunExtensions::runAsyncNoFutureInterface() { // free function pointer bool value = false; - Utils::runAsync(voidFunction, &value).waitForFinished(); + Utils::runAsync(voidFunction, &value).waitForFinished(); QCOMPARE(value, true); - QCOMPARE(Utils::runAsync(one).results(), + QCOMPARE(Utils::runAsync(one).results(), QList({1})); - QCOMPARE(Utils::runAsync(identity, 5).results(), + QCOMPARE(Utils::runAsync(identity, 5).results(), QList({5})); QString s = QLatin1String("string"); const QString &crs = QLatin1String("cr string"); const QString cs = QLatin1String("c string"); - QCOMPARE(Utils::runAsync(stringIdentity1, s).results(), + QCOMPARE(Utils::runAsync(stringIdentity1, s).results(), QList({s})); - QCOMPARE(Utils::runAsync(stringIdentity1, crs).results(), + QCOMPARE(Utils::runAsync(stringIdentity1, crs).results(), QList({crs})); - QCOMPARE(Utils::runAsync(stringIdentity1, cs).results(), + QCOMPARE(Utils::runAsync(stringIdentity1, cs).results(), QList({cs})); - QCOMPARE(Utils::runAsync(stringIdentity1, QString(QLatin1String("rvalue"))).results(), + QCOMPARE(Utils::runAsync(stringIdentity1, QString(QLatin1String("rvalue"))).results(), QList({QString(QLatin1String("rvalue"))})); - QCOMPARE(Utils::runAsync(stringIdentity2, s).results(), + QCOMPARE(Utils::runAsync(stringIdentity2, s).results(), QList({s})); - QCOMPARE(Utils::runAsync(stringIdentity2, crs).results(), + QCOMPARE(Utils::runAsync(stringIdentity2, crs).results(), QList({crs})); - QCOMPARE(Utils::runAsync(stringIdentity2, cs).results(), + QCOMPARE(Utils::runAsync(stringIdentity2, cs).results(), QList({cs})); - QCOMPARE(Utils::runAsync(stringIdentity2, QString(QLatin1String("rvalue"))).results(), + QCOMPARE(Utils::runAsync(stringIdentity2, QString(QLatin1String("rvalue"))).results(), QList({QString(QLatin1String("rvalue"))})); // lambda - QCOMPARE(Utils::runAsync([](int n) { + QCOMPARE(Utils::runAsync([](int n) -> double { return n + 1; }, 3).results(), QList({4})); @@ -440,50 +440,50 @@ void tst_RunExtensions::runAsyncNoFutureInterface() const std::function fun = [](int n) { return n + 1; }; - QCOMPARE(Utils::runAsync(fun, 2).results(), + QCOMPARE(Utils::runAsync(fun, 2).results(), QList({3})); // operator() value = false; - Utils::runAsync(CallableWithoutQFutureInterface(), &value).waitForFinished(); + Utils::runAsync(CallableWithoutQFutureInterface(), &value).waitForFinished(); QCOMPARE(value, true); value = false; const CallableWithoutQFutureInterface c{}; - Utils::runAsync(c, &value).waitForFinished(); + Utils::runAsync(c, &value).waitForFinished(); QCOMPARE(value, true); // static member functions value = false; - Utils::runAsync(&MyObjectWithoutQFutureInterface::staticMember0, &value).waitForFinished(); + Utils::runAsync(&MyObjectWithoutQFutureInterface::staticMember0, &value).waitForFinished(); QCOMPARE(value, true); - QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::staticMember1, 2).results(), + QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::staticMember1, 2).results(), QList({2})); // member functions const MyObjectWithoutQFutureInterface obj{}; value = false; - Utils::runAsync(&MyObjectWithoutQFutureInterface::member0, &obj, &value).waitForFinished(); + Utils::runAsync(&MyObjectWithoutQFutureInterface::member0, &obj, &value).waitForFinished(); QCOMPARE(value, true); - QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::member1, &obj, 4).results(), + QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::member1, &obj, 4).results(), QList({4})); - QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString1, &obj, s).results(), + QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString1, &obj, s).results(), QList({s})); - QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString1, &obj, crs).results(), + QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString1, &obj, crs).results(), QList({crs})); - QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString1, &obj, cs).results(), + QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString1, &obj, cs).results(), QList({cs})); - QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString1, &obj, QString(QLatin1String("rvalue"))).results(), + QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString1, &obj, QString(QLatin1String("rvalue"))).results(), QList({QString(QLatin1String("rvalue"))})); - QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString2, &obj, s).results(), + QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString2, &obj, s).results(), QList({s})); - QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString2, &obj, crs).results(), + QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString2, &obj, crs).results(), QList({crs})); - QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString2, &obj, cs).results(), + QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString2, &obj, cs).results(), QList({cs})); - QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString2, &obj, QString(QLatin1String("rvalue"))).results(), + QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::memberString2, &obj, QString(QLatin1String("rvalue"))).results(), QList({QString(QLatin1String("rvalue"))})); MyObjectWithoutQFutureInterface nonConstObj{}; - QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::nonConstMember, &nonConstObj, 4).results(), + QCOMPARE(Utils::runAsync(&MyObjectWithoutQFutureInterface::nonConstMember, &nonConstObj, 4).results(), QList({4})); }