summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-10-07 12:15:45 +0200
committerLars Knoll <lars.knoll@qt.io>2020-10-07 13:54:19 +0200
commit0624da584d7a5648bd6e62fd75d4cca8cdef78fe (patch)
treef7dcf116ad7e1172dc0267091a2ccac515097e52
parentbf5d52020b348d77a8968e39ca36dea7cbcef0e5 (diff)
Cleanup the comparison operators for QVariant
The code was designed to avoid implicit casts when none of the two types was a QVariant in C++98 times. This can nowadays be achieved in a better way by making the operators hidden friends of QVariant. Change-Id: I836b44027fc4ed2bfec401e94d41bddf865c431d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/corelib/kernel/qvariant.h42
1 files changed, 5 insertions, 37 deletions
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index 1bf904618f..04b93c262a 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -88,7 +88,6 @@ class QTextFormat;
class QTextLength;
class QUrl;
class QVariant;
-class QVariantComparisonHelper;
template<typename T>
inline T qvariant_cast(const QVariant &);
@@ -486,15 +485,13 @@ class Q_CORE_EXPORT QVariant
}
};
public:
- inline bool operator==(const QVariant &v) const
- { return equals(v); }
- inline bool operator!=(const QVariant &v) const
- { return !equals(v); }
-
static std::optional<int> compare(const QVariant &lhs, const QVariant &rhs);
-protected:
- friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &);
+private:
+ friend inline bool operator==(const QVariant &a, const QVariant &b)
+ { return a.equals(b); }
+ friend inline bool operator!=(const QVariant &a, const QVariant &b)
+ { return !a.equals(b); }
#ifndef QT_NO_DEBUG_STREAM
friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant &);
#endif
@@ -566,35 +563,6 @@ Q_CORE_EXPORT QDataStream& operator<< (QDataStream& s, const QVariant::Type p);
inline bool QVariant::isDetached() const
{ return !d.is_shared || d.data.shared->ref.loadRelaxed() == 1; }
-
-#ifdef Q_QDOC
- inline bool operator==(const QVariant &v1, const QVariant &v2);
- inline bool operator!=(const QVariant &v1, const QVariant &v2);
-#else
-
-/* Helper class to add one more level of indirection to prevent
- implicit casts.
-*/
-class QVariantComparisonHelper
-{
-public:
- inline QVariantComparisonHelper(const QVariant &var)
- : v(&var) {}
-private:
- friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &);
- const QVariant *v;
-};
-
-inline bool operator==(const QVariant &v1, const QVariantComparisonHelper &v2)
-{
- return v1.equals(*v2.v);
-}
-
-inline bool operator!=(const QVariant &v1, const QVariantComparisonHelper &v2)
-{
- return !operator==(v1, v2);
-}
-#endif
Q_DECLARE_SHARED(QVariant)
#ifndef QT_MOC