diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-29 11:38:09 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-29 20:25:49 +0100 |
commit | 0cd134ed91711aab662fbfea86faeb326d32a94f (patch) | |
tree | 5be919c7beaf8c21829d88d2ed99e24949eecdc7 /src/corelib/tools/qmap.h | |
parent | e53a3bd85afb0e140aa4b89925345c33dc464bf5 (diff) |
Make QMap and QMultiMap comparisons hidden friends
Task-number: QTBUG-87975
Change-Id: I3c84a188cdbb0d09e0e7c66588c7638c8a8328fd
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/tools/qmap.h')
-rw-r--r-- | src/corelib/tools/qmap.h | 90 |
1 files changed, 31 insertions, 59 deletions
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 0030c076ad..7b59688fa4 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -272,18 +272,22 @@ public: return {}; } -#ifdef Q_QDOC - template <typename AKey, typename AT> - friend bool operator==(const QMap<AKey, AT> &lhs, const QMap<AKey, AT> &rhs); - template <typename AKey, typename AT> - friend bool operator!=(const QMap<AKey, AT> &lhs, const QMap<AKey, AT> &rhs); -#else - // CHANGE: non-member equality comparison - template <typename AKey, typename AT> - friend QTypeTraits::compare_eq_result<AKey, AT> operator==(const QMap<AKey, AT> &lhs, const QMap<AKey, AT> &rhs); - template <typename AKey, typename AT> - friend QTypeTraits::compare_eq_result<AKey, AT> operator!=(const QMap<AKey, AT> &lhs, const QMap<AKey, AT> &rhs); -#endif + template <typename AKey = Key, typename AT = T> friend + QTypeTraits::compare_eq_result<AKey, AT> operator==(const QMap &lhs, const QMap &rhs) + { + if (lhs.d == rhs.d) + return true; + if (!lhs.d) + return rhs == lhs; + Q_ASSERT(lhs.d); + return rhs.d ? (lhs.d->m == rhs.d->m) : lhs.d->m.empty(); + } + + template <typename AKey = Key, typename AT = T> friend + QTypeTraits::compare_eq_result<AKey, AT> operator!=(const QMap &lhs, const QMap &rhs) + { + return !(lhs == rhs); + } // TODO: add the other comparison operators; std::map has them. size_type size() const { return d ? size_type(d->m.size()) : size_type(0); } @@ -734,24 +738,6 @@ public: Q_DECLARE_ASSOCIATIVE_ITERATOR(Map) Q_DECLARE_MUTABLE_ASSOCIATIVE_ITERATOR(Map) -template <typename AKey, typename AT> -QTypeTraits::compare_eq_result<AKey, AT> operator==(const QMap<AKey, AT> &lhs, const QMap<AKey, AT> &rhs) -{ - if (lhs.d == rhs.d) - return true; - if (!lhs.d) - return rhs == lhs; - Q_ASSERT(lhs.d); - return rhs.d ? (lhs.d->m == rhs.d->m) : lhs.d->m.empty(); -} - -template <typename AKey, typename AT> -QTypeTraits::compare_eq_result<AKey, AT> operator!=(const QMap<AKey, AT> &lhs, const QMap<AKey, AT> &rhs) -{ - return !(lhs == rhs); -} - - // // QMultiMap // @@ -848,19 +834,22 @@ public: return {}; } -#ifdef Q_QDOC - template <typename AKey, typename AT> - friend bool operator==(const QMultiMap<AKey, AT> &lhs, const QMultiMap<AKey, AT> &rhs); - template <typename AKey, typename AT> - friend bool operator!=(const QMultiMap<AKey, AT> &lhs, const QMultiMap<AKey, AT> &rhs); -#else - // CHANGE: non-member equality comparison - template <typename AKey, typename AT> - friend QTypeTraits::compare_eq_result<AKey, AT> operator==(const QMultiMap<AKey, AT> &lhs, const QMultiMap<AKey, AT> &rhs); - template <typename AKey, typename AT> - friend QTypeTraits::compare_eq_result<AKey, AT> operator!=(const QMultiMap<AKey, AT> &lhs, const QMultiMap<AKey, AT> &rhs); -#endif + template <typename AKey = Key, typename AT = T> friend + QTypeTraits::compare_eq_result<AKey, AT> operator==(const QMultiMap &lhs, const QMultiMap &rhs) + { + if (lhs.d == rhs.d) + return true; + if (!lhs.d) + return rhs == lhs; + Q_ASSERT(lhs.d); + return rhs.d ? (lhs.d->m == rhs.d->m) : lhs.d->m.empty(); + } + template <typename AKey = Key, typename AT = T> friend + QTypeTraits::compare_eq_result<AKey, AT> operator!=(const QMultiMap &lhs, const QMultiMap &rhs) + { + return !(lhs == rhs); + } // TODO: add the other comparison operators; std::multimap has them. size_type size() const { return d ? size_type(d->m.size()) : size_type(0); } @@ -1433,23 +1422,6 @@ public: Q_DECLARE_ASSOCIATIVE_ITERATOR(MultiMap) Q_DECLARE_MUTABLE_ASSOCIATIVE_ITERATOR(MultiMap) -template <typename AKey, typename AT> -QTypeTraits::compare_eq_result<AKey, AT> operator==(const QMultiMap<AKey, AT> &lhs, const QMultiMap<AKey, AT> &rhs) -{ - if (lhs.d == rhs.d) - return true; - if (!lhs.d) - return rhs == lhs; - Q_ASSERT(lhs.d); - return rhs.d ? (lhs.d->m == rhs.d->m) : lhs.d->m.empty(); -} - -template <typename AKey, typename AT> -QTypeTraits::compare_eq_result<AKey, AT> operator!=(const QMultiMap<AKey, AT> &lhs, const QMultiMap<AKey, AT> &rhs) -{ - return !(lhs == rhs); -} - template <typename Key, typename T> QMultiMap<Key, T> operator+(const QMultiMap<Key, T> &lhs, const QMultiMap<Key, T> &rhs) { |