QPromise: add support for addResult(braced-initializer)
The usual problem, the usual fix: default the addResult() template argument to the class template argument, cf. e.g. wg21.link/p2218. [ChangeLog][QtCore][QPromise] Added support for calls to addResult() with braced initializers. Fixes: QTBUG-111826 Change-Id: I9ad7294dbcefbc5d2609ca3d9e7304dbeb8b3f41 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>bb10
parent
f1e539518b
commit
f8dba0395f
|
|
@ -46,7 +46,7 @@ public:
|
|||
|
||||
// Core QPromise APIs
|
||||
QFuture<T> future() const { return d.future(); }
|
||||
template<typename U, typename = QtPrivate::EnableIfSameOrConvertible<U, T>>
|
||||
template<typename U = T, typename = QtPrivate::EnableIfSameOrConvertible<U, T>>
|
||||
bool addResult(U &&result, int index = -1)
|
||||
{
|
||||
return d.reportResult(std::forward<U>(result), index);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ private slots:
|
|||
void promise();
|
||||
void futureFromPromise();
|
||||
void addResult();
|
||||
void addResultWithBracedInitializer();
|
||||
void addResultOutOfOrder();
|
||||
#ifndef QT_NO_EXCEPTIONS
|
||||
void setException();
|
||||
|
|
@ -196,6 +197,20 @@ void tst_QPromise::addResult()
|
|||
}
|
||||
}
|
||||
|
||||
void tst_QPromise::addResultWithBracedInitializer() // QTBUG-111826
|
||||
{
|
||||
struct MyClass
|
||||
{
|
||||
QString strValue;
|
||||
int intValue = 0;
|
||||
};
|
||||
|
||||
{
|
||||
QPromise<MyClass> myPromise;
|
||||
myPromise.addResult({"bar", 1});
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QPromise::addResultOutOfOrder()
|
||||
{
|
||||
// Compare results available in QFuture to expected results
|
||||
|
|
|
|||
Loading…
Reference in New Issue