From cab0d26c45f19e71fcf4df2ad9532d93b497c5ca Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 12 Dec 2023 09:20:30 +0100 Subject: [PATCH] QMap/QHash: s/QPair/std::pair/ Also port from qMakePair to just braced initialization using CTAD. Task-number: QTBUG-115841 Change-Id: Ib0ad55d7110521e34004dc9050022f9c0046722e Reviewed-by: Ahmad Samir (cherry picked from commit 0d1575828015f99a495af84fb7de3746c7f61717) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qhash.cpp | 12 ++++++------ src/corelib/tools/qhash.h | 20 ++++++++++---------- src/corelib/tools/qmap.h | 8 ++++---- src/corelib/tools/qmap.qdoc | 4 ++-- src/corelib/tools/qmultimap.qdoc | 4 ++-- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 6d8d587e528..fe994f68b85 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -1783,8 +1783,8 @@ size_t qHash(long double key, size_t seed) noexcept Constructs a hash with a copy of each of the elements in the iterator range [\a begin, \a end). Either the elements iterated by the range must be - objects with \c{first} and \c{second} data members (like \c{QPair}, - \c{std::pair}, etc.) convertible to \c Key and to \c T respectively; or the + objects with \c{first} and \c{second} data members (like \c{std::pair}), + convertible to \c Key and to \c T respectively; or the iterators must have \c{key()} and \c{value()} member functions, returning a key convertible to \c Key and a value convertible to \c T respectively. */ @@ -2362,7 +2362,7 @@ size_t qHash(long double key, size_t seed) noexcept returns \c false. */ -/*! \fn template QPair QMultiHash::equal_range(const Key &key) +/*! \fn template std::pair QMultiHash::equal_range(const Key &key) \since 5.7 Returns a pair of iterators delimiting the range of values \c{[first, second)}, that @@ -2370,7 +2370,7 @@ size_t qHash(long double key, size_t seed) noexcept */ /*! - \fn template QPair QMultiHash::equal_range(const Key &key) const + \fn template std::pair QMultiHash::equal_range(const Key &key) const \overload \since 5.7 */ @@ -2955,8 +2955,8 @@ size_t qHash(long double key, size_t seed) noexcept Constructs a multi-hash with a copy of each of the elements in the iterator range [\a begin, \a end). Either the elements iterated by the range must be - objects with \c{first} and \c{second} data members (like \c{QPair}, - \c{std::pair}, etc.) convertible to \c Key and to \c T respectively; or the + objects with \c{first} and \c{second} data members (like \c{std::pair}), + convertible to \c Key and to \c T respectively; or the iterators must have \c{key()} and \c{value()} member functions, returning a key convertible to \c Key and a value convertible to \c T respectively. */ diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index a4de3e377cf..72fdb70c542 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -1234,22 +1234,22 @@ public: return i; } - QPair equal_range(const Key &key) + std::pair equal_range(const Key &key) { auto first = find(key); auto second = first; if (second != iterator()) ++second; - return qMakePair(first, second); + return {first, second}; } - QPair equal_range(const Key &key) const noexcept + std::pair equal_range(const Key &key) const noexcept { auto first = find(key); auto second = first; if (second != iterator()) ++second; - return qMakePair(first, second); + return {first, second}; } typedef iterator Iterator; @@ -2125,26 +2125,26 @@ public: return *this; } - QPair equal_range(const Key &key) + std::pair equal_range(const Key &key) { const auto copy = isDetached() ? QMultiHash() : *this; // keep 'key' alive across the detach detach(); auto pair = std::as_const(*this).equal_range(key); - return qMakePair(iterator(pair.first.i), iterator(pair.second.i)); + return {iterator(pair.first.i), iterator(pair.second.i)}; } - QPair equal_range(const Key &key) const noexcept + std::pair equal_range(const Key &key) const noexcept { if (!d) - return qMakePair(end(), end()); + return {end(), end()}; auto bucket = d->findBucket(key); if (bucket.isUnused()) - return qMakePair(end(), end()); + return {end(), end()}; auto it = bucket.toIterator(d); auto end = it; ++end; - return qMakePair(const_iterator(it), const_iterator(end)); + return {const_iterator(it), const_iterator(end)}; } private: diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 1a6506348f1..436aa18cfd0 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -762,7 +762,7 @@ public: return isEmpty(); } - QPair equal_range(const Key &akey) + std::pair equal_range(const Key &akey) { const auto copy = d.isShared() ? *this : QMap(); // keep `key` alive across the detach detach(); @@ -770,7 +770,7 @@ public: return {iterator(result.first), iterator(result.second)}; } - QPair equal_range(const Key &akey) const + std::pair equal_range(const Key &akey) const { if (!d) return {}; @@ -1492,7 +1492,7 @@ public: // STL compatibility inline bool empty() const { return isEmpty(); } - QPair equal_range(const Key &akey) + std::pair equal_range(const Key &akey) { const auto copy = d.isShared() ? *this : QMultiMap(); // keep `key` alive across the detach detach(); @@ -1500,7 +1500,7 @@ public: return {iterator(result.first), iterator(result.second)}; } - QPair equal_range(const Key &akey) const + std::pair equal_range(const Key &akey) const { if (!d) return {}; diff --git a/src/corelib/tools/qmap.qdoc b/src/corelib/tools/qmap.qdoc index b9d0bd23619..ec1ed8f46e2 100644 --- a/src/corelib/tools/qmap.qdoc +++ b/src/corelib/tools/qmap.qdoc @@ -818,14 +818,14 @@ */ /*! - \fn template QPair::iterator, typename QMap::iterator> QMap::equal_range(const Key &key) + \fn template std::pair::iterator, typename QMap::iterator> QMap::equal_range(const Key &key) Returns a pair of iterators delimiting the range of values \c{[first, second)}, that are stored under \a key. */ /*! - \fn template QPair::const_iterator, typename QMap::const_iterator> QMap::equal_range(const Key &key) const + \fn template std::pair::const_iterator, typename QMap::const_iterator> QMap::equal_range(const Key &key) const \overload \since 5.6 */ diff --git a/src/corelib/tools/qmultimap.qdoc b/src/corelib/tools/qmultimap.qdoc index 6373b2748df..64ead329a2b 100644 --- a/src/corelib/tools/qmultimap.qdoc +++ b/src/corelib/tools/qmultimap.qdoc @@ -934,14 +934,14 @@ */ /*! - \fn template QPair::iterator, typename QMultiMap::iterator> QMultiMap::equal_range(const Key &key) + \fn template std::pair::iterator, typename QMultiMap::iterator> QMultiMap::equal_range(const Key &key) Returns a pair of iterators delimiting the range of values \c{[first, second)}, that are stored under \a key. */ /*! - \fn template QPair::const_iterator, typename QMultiMap::const_iterator> QMultiMap::equal_range(const Key &key) const + \fn template std::pair::const_iterator, typename QMultiMap::const_iterator> QMultiMap::equal_range(const Key &key) const \overload \since 5.6 */