summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-15 11:35:10 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-16 13:53:02 +0200
commit382e3cb00f8703cd9b1774617e83bee7c44d87cf (patch)
tree88a63e76509d6c0205e926c0a41754fad1f14d69 /src
parent8ff44b3aea9107d1cef55ae49b73c923540e8209 (diff)
Add comparison operators to shared data pointers
To avoid they are compared as bools, or ambiguously. Change-Id: I1495b3126a71c1379e72d4cf53b1a67590eb9f4b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qshareddata.h60
1 files changed, 28 insertions, 32 deletions
diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h
index 809e8171e3..669d9d14c4 100644
--- a/src/corelib/tools/qshareddata.h
+++ b/src/corelib/tools/qshareddata.h
@@ -44,6 +44,8 @@
#include <QtCore/qatomic.h>
#include <QtCore/qhashfunctions.h>
+#include <functional>
+
QT_BEGIN_NAMESPACE
@@ -120,18 +122,25 @@ public:
void swap(QSharedDataPointer &other) noexcept
{ qSwap(d, other.d); }
- friend bool operator==(const QSharedDataPointer &p1, const QSharedDataPointer &p2) noexcept
- { return p1.d == p2.d; }
- friend bool operator!=(const QSharedDataPointer &p1, const QSharedDataPointer &p2) noexcept
- { return p1.d != p2.d; }
- friend bool operator==(const QSharedDataPointer &p1, std::nullptr_t) noexcept
- { return !p1; }
- friend bool operator!=(const QSharedDataPointer &p1, std::nullptr_t) noexcept
- { return p1; }
- friend bool operator==(std::nullptr_t, const QSharedDataPointer &p2) noexcept
- { return !p2; }
- friend bool operator!=(std::nullptr_t, const QSharedDataPointer &p2) noexcept
- { return p2; }
+#define DECLARE_COMPARE_SET(T1, A1, T2, A2) \
+ friend bool operator<(T1, T2) noexcept \
+ { return std::less<T*>{}(A1, A2); } \
+ friend bool operator<=(T1, T2) noexcept \
+ { return !std::less<T*>{}(A2, A1); } \
+ friend bool operator>(T1, T2) noexcept \
+ { return std::less<T*>{}(A2, A1); } \
+ friend bool operator>=(T1, T2) noexcept \
+ { return !std::less<T*>{}(A1, A2); } \
+ friend bool operator==(T1, T2) noexcept \
+ { return A1 == A2; } \
+ friend bool operator!=(T1, T2) noexcept \
+ { return A1 != A2; } \
+
+ DECLARE_COMPARE_SET(const QSharedDataPointer &p1, p1.d, const QSharedDataPointer &p2, p2.d)
+ DECLARE_COMPARE_SET(const QSharedDataPointer &p1, p1.d, const T *ptr, ptr)
+ DECLARE_COMPARE_SET(const T *ptr, ptr, const QSharedDataPointer &p2, p2.d)
+ DECLARE_COMPARE_SET(const QSharedDataPointer &p1, p1.d, std::nullptr_t, nullptr)
+ DECLARE_COMPARE_SET(std::nullptr_t, nullptr, const QSharedDataPointer &p2, p2.d)
protected:
T *clone();
@@ -208,26 +217,13 @@ public:
void swap(QExplicitlySharedDataPointer &other) noexcept
{ qSwap(d, other.d); }
- friend bool operator==(const QExplicitlySharedDataPointer &p1, const QExplicitlySharedDataPointer &p2) noexcept
- { return p1.d == p2.d; }
- friend bool operator!=(const QExplicitlySharedDataPointer &p1, const QExplicitlySharedDataPointer &p2) noexcept
- { return p1.d != p2.d; }
- friend bool operator==(const QExplicitlySharedDataPointer &p1, const T *ptr) noexcept
- { return p1.d == ptr; }
- friend bool operator!=(const QExplicitlySharedDataPointer &p1, const T *ptr) noexcept
- { return p1.d != ptr; }
- friend bool operator==(const T *ptr, const QExplicitlySharedDataPointer &p2) noexcept
- { return ptr == p2.d; }
- friend bool operator!=(const T *ptr, const QExplicitlySharedDataPointer &p2) noexcept
- { return ptr != p2.d; }
- friend bool operator==(const QExplicitlySharedDataPointer &p1, std::nullptr_t) noexcept
- { return !p1; }
- friend bool operator!=(const QExplicitlySharedDataPointer &p1, std::nullptr_t) noexcept
- { return p1; }
- friend bool operator==(std::nullptr_t, const QExplicitlySharedDataPointer &p2) noexcept
- { return !p2; }
- friend bool operator!=(std::nullptr_t, const QExplicitlySharedDataPointer &p2) noexcept
- { return p2; }
+ DECLARE_COMPARE_SET(const QExplicitlySharedDataPointer &p1, p1.d, const QExplicitlySharedDataPointer &p2, p2.d)
+ DECLARE_COMPARE_SET(const QExplicitlySharedDataPointer &p1, p1.d, const T *ptr, ptr)
+ DECLARE_COMPARE_SET(const T *ptr, ptr, const QExplicitlySharedDataPointer &p2, p2.d)
+ DECLARE_COMPARE_SET(const QExplicitlySharedDataPointer &p1, p1.d, std::nullptr_t, nullptr)
+ DECLARE_COMPARE_SET(std::nullptr_t, nullptr, const QExplicitlySharedDataPointer &p2, p2.d)
+
+#undef DECLARE_COMPARE_SET
protected:
T *clone();