From c34316243e35223d446e0fb06ffee014ec604e08 Mon Sep 17 00:00:00 2001 From: Simon Brunel Date: Fri, 9 Feb 2018 23:18:05 +0100 Subject: [PATCH] Make QPromise::all accept more container types Currently, QPromise can't be added dynamically to QVector (::push_* | ::append) because it doesn't expose a default constructor. Until deciding if a default constructor should be added (private/public?), let's make the `QPromise::all` method work with any container types that are STL compatible. --- README.md | 6 +- src/qtpromise/qpromise.h | 8 +- src/qtpromise/qpromise.inl | 19 ++-- src/qtpromise/qpromisehelpers.h | 7 +- tests/auto/qtpromise/qpromise/all/all.pro | 4 + tests/auto/qtpromise/qpromise/all/tst_all.cpp | 103 ++++++++++++++++++ tests/auto/qtpromise/qpromise/qpromise.pro | 1 + 7 files changed, 134 insertions(+), 14 deletions(-) create mode 100644 tests/auto/qtpromise/qpromise/all/all.pro create mode 100644 tests/auto/qtpromise/qpromise/all/tst_all.cpp diff --git a/README.md b/README.md index b3cbda7..ce7efea 100644 --- a/README.md +++ b/README.md @@ -385,9 +385,11 @@ QPromise compute(const QString& type) } ``` -### `[static] QPromise::all(QVector>) -> QPromise>` +### `[static] QPromise::all(Sequence>) -> QPromise>` Returns a `QPromise>` that fulfills when **all** `promises` of (the same) type `T` have been fulfilled. The `output` value is a vector containing **all** the values of `promises`, in the same order. If any of the given `promises` fail, `output` immediately rejects with the error of the promise that rejected, whether or not the other promises are resolved. +`Sequence` is any STL compatible container (eg. `QVector`, `QList`, `std::vector`, etc.) + ```cpp QVector > promises{ download(QUrl("http://a...")), @@ -417,7 +419,7 @@ auto promise = qPromise(QString("foo")); // QPromise This method also allows to convert `QFuture` to `QPromise` delayed until the `QFuture` is finished ([read more](#qtconcurrent-convert)). -### `qPromiseAll(QVector promises) -> QPromise>` +### `qPromiseAll(Sequence promises) -> QPromise>` This method simply calls the appropriated [`QPromise::all`](#qpromise-all) static method based on the given `QVector` type. In some cases, this method is more convenient than the static one since it avoid some extra typing: ```cpp diff --git a/src/qtpromise/qpromise.h b/src/qtpromise/qpromise.h index d1c110f..ed7d7c5 100644 --- a/src/qtpromise/qpromise.h +++ b/src/qtpromise/qpromise.h @@ -85,7 +85,9 @@ public: QPromise(F&& resolver): QPromiseBase(std::forward(resolver)) { } public: // STATIC - inline static QPromise > all(const QVector >& promises); + template