Deprecate QVariant::operator< and related operators

Since the operator does not have a total order, it is kind of pointless,
and this is going to be removed in Qt6

Change-Id: I754be059726bf30993550a2d753f8b865f2d4a5f
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
Olivier Goffart 2019-11-23 12:28:07 +01:00
parent de6520805a
commit f43cb31ba0
2 changed files with 20 additions and 4 deletions

View File

@ -3829,6 +3829,7 @@ bool QVariant::convert(const int type, void *ptr) const
/*!
\fn bool QVariant::operator<(const QVariant &v) const
\obsolete
Compares this QVariant with \a v and returns \c true if this is less than \a v.
@ -3838,10 +3839,15 @@ bool QVariant::convert(const int type, void *ptr) const
\warning To make this function work with a custom type registered with
qRegisterMetaType(), its comparison operator must be registered using
QMetaType::registerComparators().
This operator is deprecated as it cannot establish a total order required
for most use of this operator, which is the reason you cannot use QVariant
as the key of a QMap.
*/
/*!
\fn bool QVariant::operator<=(const QVariant &v) const
\obsolete
Compares this QVariant with \a v and returns \c true if this is less or equal than \a v.
@ -3851,10 +3857,13 @@ bool QVariant::convert(const int type, void *ptr) const
\warning To make this function work with a custom type registered with
qRegisterMetaType(), its comparison operator must be registered using
QMetaType::registerComparators().
This operator is deprecated as it cannot establish a total order.
*/
/*!
\fn bool QVariant::operator>(const QVariant &v) const
\obsolete
Compares this QVariant with \a v and returns \c true if this is larger than \a v.
@ -3864,10 +3873,13 @@ bool QVariant::convert(const int type, void *ptr) const
\warning To make this function work with a custom type registered with
qRegisterMetaType(), its comparison operator must be registered using
QMetaType::registerComparators().
This operator is deprecated as it cannot establish a total order.
*/
/*!
\fn bool QVariant::operator>=(const QVariant &v) const
\obsolete
Compares this QVariant with \a v and returns \c true if this is larger or equal than \a v.
@ -3877,6 +3889,8 @@ bool QVariant::convert(const int type, void *ptr) const
\warning To make this function work with a custom type registered with
qRegisterMetaType(), its comparison operator must be registered using
QMetaType::registerComparators().
This operator is deprecated as it cannot establish a total order.
*/
static bool qIsNumericType(uint tp)

View File

@ -463,14 +463,16 @@ class Q_CORE_EXPORT QVariant
{ return cmp(v); }
inline bool operator!=(const QVariant &v) const
{ return !cmp(v); }
inline bool operator<(const QVariant &v) const
#if QT_DEPRECATED_SINCE(5, 15)
QT_DEPRECATED inline bool operator<(const QVariant &v) const
{ return compare(v) < 0; }
inline bool operator<=(const QVariant &v) const
QT_DEPRECATED inline bool operator<=(const QVariant &v) const
{ return compare(v) <= 0; }
inline bool operator>(const QVariant &v) const
QT_DEPRECATED inline bool operator>(const QVariant &v) const
{ return compare(v) > 0; }
inline bool operator>=(const QVariant &v) const
QT_DEPRECATED inline bool operator>=(const QVariant &v) const
{ return compare(v) >= 0; }
#endif
protected:
friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &);