From e356ab2c32248838f70fce38b35294a151a7e278 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 22 Oct 2020 09:02:02 +0200 Subject: Make QPointer comparisons hidden friends Reduces ADL noise. Change-Id: Id0aa4b32b7bb6d70ed9106b949452d895d9060a9 Reviewed-by: Volker Hilsheimer --- src/corelib/kernel/qpointer.h | 62 +++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 40 deletions(-) (limited to 'src/corelib/kernel/qpointer.h') 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 \ + friend bool operator==(T1, T2) noexcept \ + { return A1 == A2; } \ + template \ + friend bool operator!=(T1, T2) noexcept \ + { return A1 != A2; } + + DECLARE_TEMPLATE_COMPARE_SET(const QPointer &p1, p1.data(), const QPointer &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 Q_DECLARE_TYPEINFO_BODY(QPointer, Q_MOVABLE_TYPE); -template -inline bool operator==(const T *o, const QPointer &p) -{ return o == p.operator->(); } - -template -inline bool operator==(const QPointer &p, const T *o) -{ return p.operator->() == o; } - -template -inline bool operator==(T *o, const QPointer &p) -{ return o == p.operator->(); } - -template -inline bool operator==(const QPointer &p, T *o) -{ return p.operator->() == o; } - -template -inline bool operator==(const QPointer &p1, const QPointer &p2) -{ return p1.operator->() == p2.operator->(); } - -template -inline bool operator!=(const T *o, const QPointer &p) -{ return o != p.operator->(); } - -template -inline bool operator!= (const QPointer &p, const T *o) -{ return p.operator->() != o; } - -template -inline bool operator!=(T *o, const QPointer &p) -{ return o != p.operator->(); } - -template -inline bool operator!= (const QPointer &p, T *o) -{ return p.operator->() != o; } - -template -inline bool operator!= (const QPointer &p1, const QPointer &p2) -{ return p1.operator->() != p2.operator->() ; } - template QPointer qPointerFromVariant(const QVariant &variant) -- cgit v1.2.3