Commit 4b077921 authored by Eike Ziller's avatar Eike Ziller
Browse files

runAsync: Allow function references, and non-const parameters.



Change-Id: I258259da7767087a8319d6a4489aa4d6c3b32c6f
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent e90ef403
......@@ -561,8 +561,8 @@ QFuture<ResultType> runAsync(Function &&function, Args&&... args)
{
QFutureInterface<ResultType> futureInterface;
futureInterface.reportStarted();
std::thread(Internal::runAsyncImpl<ResultType,Function,Args...>, futureInterface,
std::forward<Function>(function), std::forward<Args>(args)...).detach();
std::thread(Internal::runAsyncImpl<ResultType,typename std::decay<Function>::type,typename std::decay<Args>::type...>,
futureInterface, std::forward<Function>(function), std::forward<Args>(args)...).detach();
return futureInterface.future();
}
......
......@@ -525,7 +525,7 @@ void LocatorWidget::updateCompletionList(const QString &text)
foreach (ILocatorFilter *filter, filters)
filter->prepareSearch(searchText);
QFuture<LocatorFilterEntry> future = Utils::runAsync<LocatorFilterEntry>(&runSearch, filters,
QString(searchText));
searchText);
m_entriesWatcher->setFuture(future);
}
......
......@@ -73,32 +73,34 @@ void tst_RunExtensions::runAsync()
// free function pointer
QCOMPARE(Utils::runAsync<int>(&report3).results(),
QList<int>({0, 2, 1}));
QCOMPARE(Utils::runAsync<int>(report3).results(),
QList<int>({0, 2, 1}));
QCOMPARE(Utils::runAsync<double>(&reportN, 4).results(),
QCOMPARE(Utils::runAsync<double>(reportN, 4).results(),
QList<double>({0, 0, 0, 0}));
QCOMPARE(Utils::runAsync<double>(&reportN, 2).results(),
QCOMPARE(Utils::runAsync<double>(reportN, 2).results(),
QList<double>({0, 0}));
QString s = QLatin1String("string");
const QString &crs = QLatin1String("cr string");
const QString cs = QLatin1String("c string");
QCOMPARE(Utils::runAsync<QString>(&reportString1, std::cref(s)).results(),
QCOMPARE(Utils::runAsync<QString>(reportString1, s).results(),
QList<QString>({s}));
QCOMPARE(Utils::runAsync<QString>(&reportString1, crs).results(),
QCOMPARE(Utils::runAsync<QString>(reportString1, crs).results(),
QList<QString>({crs}));
QCOMPARE(Utils::runAsync<QString>(&reportString1, cs).results(),
QCOMPARE(Utils::runAsync<QString>(reportString1, cs).results(),
QList<QString>({cs}));
QCOMPARE(Utils::runAsync<QString>(&reportString1, QString(QLatin1String("rvalue"))).results(),
QCOMPARE(Utils::runAsync<QString>(reportString1, QString(QLatin1String("rvalue"))).results(),
QList<QString>({QString(QLatin1String("rvalue"))}));
QCOMPARE(Utils::runAsync<QString>(&reportString2, std::cref(s)).results(),
QCOMPARE(Utils::runAsync<QString>(reportString2, s).results(),
QList<QString>({s}));
QCOMPARE(Utils::runAsync<QString>(&reportString2, crs).results(),
QCOMPARE(Utils::runAsync<QString>(reportString2, crs).results(),
QList<QString>({crs}));
QCOMPARE(Utils::runAsync<QString>(&reportString2, cs).results(),
QCOMPARE(Utils::runAsync<QString>(reportString2, cs).results(),
QList<QString>({cs}));
QCOMPARE(Utils::runAsync<QString>(&reportString2, QString(QLatin1String("rvalue"))).results(),
QCOMPARE(Utils::runAsync<QString>(reportString2, QString(QLatin1String("rvalue"))).results(),
QList<QString>({QString(QLatin1String("rvalue"))}));
// lambda
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment