summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qpointer.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-22 09:02:02 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-23 09:32:37 +0200
commite356ab2c32248838f70fce38b35294a151a7e278 (patch)
tree896b4f19ddf2f9696127b073abf2dc8f6c159ac3 /src/corelib/kernel/qpointer.h
parent2516fc935cfa77bd42e9cededf7e8be8c0980e13 (diff)
Make QPointer comparisons hidden friends
Reduces ADL noise. Change-Id: Id0aa4b32b7bb6d70ed9106b949452d895d9060a9 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/kernel/qpointer.h')
-rw-r--r--src/corelib/kernel/qpointer.h62
1 files changed, 22 insertions, 40 deletions
diff --git a/src/corelib/kernel/qpointer.h b/src/corelib/kernel/qpointer.h
index ebc06a0fb1..30c7d923fd 100644
--- a/src/corelib/kernel/qpointer.h
+++ b/src/corelib/kernel/qpointer.h
@@ -89,49 +89,31 @@ public:
inline void clear()
{ wp.clear(); }
+
+#define DECLARE_COMPARE_SET(T1, A1, T2, A2) \
+ friend bool operator==(T1, T2) \
+ { return A1 == A2; } \
+ friend bool operator!=(T1, T2) \
+ { return A1 != A2; }
+
+#define DECLARE_TEMPLATE_COMPARE_SET(T1, A1, T2, A2) \
+ template <typename X> \
+ friend bool operator==(T1, T2) noexcept \
+ { return A1 == A2; } \
+ template <typename X> \
+ friend bool operator!=(T1, T2) noexcept \
+ { return A1 != A2; }
+
+ DECLARE_TEMPLATE_COMPARE_SET(const QPointer &p1, p1.data(), const QPointer<X> &p2, p2.data())
+ DECLARE_TEMPLATE_COMPARE_SET(const QPointer &p1, p1.data(), X *ptr, ptr)
+ DECLARE_TEMPLATE_COMPARE_SET(X *ptr, ptr, const QPointer &p2, p2.data())
+ DECLARE_COMPARE_SET(const QPointer &p1, p1.data(), std::nullptr_t, nullptr)
+ DECLARE_COMPARE_SET(std::nullptr_t, nullptr, const QPointer &p2, p2.data())
+#undef DECLARE_COMPARE_SET
+#undef DECLARE_TEMPLATE_COMPARE_SET
};
template <class T> Q_DECLARE_TYPEINFO_BODY(QPointer<T>, Q_MOVABLE_TYPE);
-template <class T>
-inline bool operator==(const T *o, const QPointer<T> &p)
-{ return o == p.operator->(); }
-
-template<class T>
-inline bool operator==(const QPointer<T> &p, const T *o)
-{ return p.operator->() == o; }
-
-template <class T>
-inline bool operator==(T *o, const QPointer<T> &p)
-{ return o == p.operator->(); }
-
-template<class T>
-inline bool operator==(const QPointer<T> &p, T *o)
-{ return p.operator->() == o; }
-
-template<class T>
-inline bool operator==(const QPointer<T> &p1, const QPointer<T> &p2)
-{ return p1.operator->() == p2.operator->(); }
-
-template <class T>
-inline bool operator!=(const T *o, const QPointer<T> &p)
-{ return o != p.operator->(); }
-
-template<class T>
-inline bool operator!= (const QPointer<T> &p, const T *o)
-{ return p.operator->() != o; }
-
-template <class T>
-inline bool operator!=(T *o, const QPointer<T> &p)
-{ return o != p.operator->(); }
-
-template<class T>
-inline bool operator!= (const QPointer<T> &p, T *o)
-{ return p.operator->() != o; }
-
-template<class T>
-inline bool operator!= (const QPointer<T> &p1, const QPointer<T> &p2)
-{ return p1.operator->() != p2.operator->() ; }
-
template<typename T>
QPointer<T>
qPointerFromVariant(const QVariant &variant)