summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qpointer.h
diff options
context:
space:
mode:
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)