diff options
Diffstat (limited to 'src/corelib/thread/qresultstore.h')
-rw-r--r-- | src/corelib/thread/qresultstore.h | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/corelib/thread/qresultstore.h b/src/corelib/thread/qresultstore.h index f633ed7801..f21068206f 100644 --- a/src/corelib/thread/qresultstore.h +++ b/src/corelib/thread/qresultstore.h @@ -46,12 +46,21 @@ public: ResultIteratorBase operator++(); int batchSize() const; void batchedAdvance(); +#if QT_CORE_REMOVED_SINCE(6, 8) bool operator==(const ResultIteratorBase &other) const; bool operator!=(const ResultIteratorBase &other) const; +#endif bool isVector() const; bool canIncrementVectorIndex() const; bool isValid() const; +private: + friend bool comparesEqual(const ResultIteratorBase &lhs, + const ResultIteratorBase &rhs) noexcept + { + return (lhs.mapIterator == rhs.mapIterator && lhs.m_vectorIndex == rhs.m_vectorIndex); + } + Q_DECLARE_EQUALITY_COMPARABLE(ResultIteratorBase) protected: QMap<int, ResultItem>::const_iterator mapIterator; int m_vectorIndex; @@ -71,7 +80,7 @@ public: template <typename T> T *pointer() { - const T *p = qAsConst(*this).pointer<T>(); + const T *p = std::as_const(*this).pointer<T>(); return const_cast<T *>(p); } @@ -134,6 +143,14 @@ protected: } public: + template <typename T, typename...Args> + int emplaceResult(int index, Args&&...args) + { + if (containsValidResultItem(index)) // reject if already present + return -1; + return addResult(index, static_cast<void *>(new T(std::forward<Args>(args)...))); + } + template <typename T> int addResult(int index, const T *result) { @@ -149,10 +166,9 @@ public: template <typename T> int moveResult(int index, T &&result) { - if (containsValidResultItem(index)) // reject if already present - return -1; + static_assert(!std::is_reference_v<T>, "trying to move from an lvalue!"); - return addResult(index, static_cast<void *>(new T(std::move_if_noexcept(result)))); + return emplaceResult<std::remove_cv_t<T>>(index, std::forward<T>(result)); } template<typename T> @@ -164,23 +180,23 @@ public: if (containsValidResultItem(index)) // reject if already present return -1; - return addResults(index, new QList<T>(*results), results->count(), results->count()); + return addResults(index, new QList<T>(*results), results->size(), results->size()); } template<typename T> int addResults(int index, const QList<T> *results, int totalCount) { // reject if results are empty, and nothing is filtered away - if ((m_filterMode == false || results->count() == totalCount) && results->empty()) + if ((m_filterMode == false || results->size() == totalCount) && results->empty()) return -1; if (containsValidResultItem(index)) // reject if already present return -1; - if (m_filterMode == true && results->count() != totalCount && 0 == results->count()) + if (m_filterMode == true && results->size() != totalCount && 0 == results->size()) return addResults(index, nullptr, 0, totalCount); - return addResults(index, new QList<T>(*results), results->count(), totalCount); + return addResults(index, new QList<T>(*results), results->size(), totalCount); } int addCanceledResult(int index) |