Rename Q*Ordering to Qt::*_ordering

Since we cannot re-use the pre-existing QPartialOrdering type due to
binary-compatibility issues (it's not BC to std::partial_ordering),
we're no longer bound to copy its API for consistency.

So copy std::*_ordering type API for consistency instead, to ease
porting for users that can already use C++20 and everyone else come
Qt 7.

This patch is another step in that direction, renaming classes and
their memmbers to std-compatible names. QPartialOrdering cannot
change, as it's pre-existing. So add a completely new type
Qt::partial_ordering.

Adding conversions from QPartialOrdering is left for a follow-up
patch.

As a drive-by, change `\c Less` to `\l Less` in the \class
documentation blocks of the new classes.

Amending c6fe64b17c, which didn't have a
ChangeLog:

[ChangeLog][QtCore] Added Qt::{partial,weak,strong}_ordering as
drop-in C++17 stand-ins for C++20's std::{partial,weak,strong}_ordering.

Task-number: QTBUG-119108
Change-Id: Ib1296de6b708571a6abca8843ba36c114f6fd34f
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
Marc Mutz 2023-11-14 14:02:27 +01:00
parent 67072a70af
commit bdd41f491c
7 changed files with 940 additions and 538 deletions

View File

@ -142,9 +142,6 @@ public:
#endif // __cpp_lib_three_way_comparison #endif // __cpp_lib_three_way_comparison
private: private:
friend class QWeakOrdering;
friend class QStrongOrdering;
constexpr explicit QPartialOrdering(QtPrivate::Ordering order) noexcept constexpr explicit QPartialOrdering(QtPrivate::Ordering order) noexcept
: m_order(static_cast<QtPrivate::CompareUnderlyingType>(order)) : m_order(static_cast<QtPrivate::CompareUnderlyingType>(order))
{} {}
@ -176,86 +173,226 @@ inline constexpr QPartialOrdering QPartialOrdering::Equivalent(QtPrivate::Orderi
inline constexpr QPartialOrdering QPartialOrdering::Greater(QtPrivate::Ordering::Greater); inline constexpr QPartialOrdering QPartialOrdering::Greater(QtPrivate::Ordering::Greater);
inline constexpr QPartialOrdering QPartialOrdering::Unordered(QtPrivate::Uncomparable::Unordered); inline constexpr QPartialOrdering QPartialOrdering::Unordered(QtPrivate::Uncomparable::Unordered);
class QWeakOrdering namespace Qt {
class partial_ordering
{ {
public: public:
static const QWeakOrdering Less; static const partial_ordering less;
static const QWeakOrdering Equivalent; static const partial_ordering equivalent;
static const QWeakOrdering Greater; static const partial_ordering greater;
static const partial_ordering unordered;
constexpr Q_IMPLICIT operator QPartialOrdering() const noexcept friend constexpr bool operator==(partial_ordering lhs,
{ return QPartialOrdering(static_cast<QtPrivate::Ordering>(m_order)); } QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.isOrdered() && lhs.m_order == 0; }
friend constexpr bool operator==(QWeakOrdering lhs, friend constexpr bool operator!=(partial_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.isOrdered() && lhs.m_order != 0; }
friend constexpr bool operator< (partial_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.isOrdered() && lhs.m_order < 0; }
friend constexpr bool operator<=(partial_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.isOrdered() && lhs.m_order <= 0; }
friend constexpr bool operator> (partial_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.isOrdered() && lhs.m_order > 0; }
friend constexpr bool operator>=(partial_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.isOrdered() && lhs.m_order >= 0; }
friend constexpr bool operator==(QtPrivate::CompareAgainstLiteralZero,
partial_ordering rhs) noexcept
{ return rhs.isOrdered() && 0 == rhs.m_order; }
friend constexpr bool operator!=(QtPrivate::CompareAgainstLiteralZero,
partial_ordering rhs) noexcept
{ return rhs.isOrdered() && 0 != rhs.m_order; }
friend constexpr bool operator< (QtPrivate::CompareAgainstLiteralZero,
partial_ordering rhs) noexcept
{ return rhs.isOrdered() && 0 < rhs.m_order; }
friend constexpr bool operator<=(QtPrivate::CompareAgainstLiteralZero,
partial_ordering rhs) noexcept
{ return rhs.isOrdered() && 0 <= rhs.m_order; }
friend constexpr bool operator> (QtPrivate::CompareAgainstLiteralZero,
partial_ordering rhs) noexcept
{ return rhs.isOrdered() && 0 > rhs.m_order; }
friend constexpr bool operator>=(QtPrivate::CompareAgainstLiteralZero,
partial_ordering rhs) noexcept
{ return rhs.isOrdered() && 0 >= rhs.m_order; }
friend constexpr bool operator==(partial_ordering lhs, partial_ordering rhs) noexcept
{ return lhs.m_order == rhs.m_order; }
friend constexpr bool operator!=(partial_ordering lhs, partial_ordering rhs) noexcept
{ return lhs.m_order != rhs.m_order; }
#ifdef __cpp_lib_three_way_comparison
constexpr Q_IMPLICIT partial_ordering(std::partial_ordering stdorder) noexcept
{
if (stdorder == std::partial_ordering::less)
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Less);
else if (stdorder == std::partial_ordering::equivalent)
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Equivalent);
else if (stdorder == std::partial_ordering::greater)
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Greater);
else if (stdorder == std::partial_ordering::unordered)
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Uncomparable::Unordered);
}
constexpr Q_IMPLICIT operator std::partial_ordering() const noexcept
{
if (static_cast<QtPrivate::Ordering>(m_order) == QtPrivate::Ordering::Less)
return std::partial_ordering::less;
else if (static_cast<QtPrivate::Ordering>(m_order) == QtPrivate::Ordering::Equivalent)
return std::partial_ordering::equivalent;
else if (static_cast<QtPrivate::Ordering>(m_order) == QtPrivate::Ordering::Greater)
return std::partial_ordering::greater;
else if (static_cast<QtPrivate::Uncomparable>(m_order) == QtPrivate::Uncomparable::Unordered)
return std::partial_ordering::unordered;
return std::partial_ordering::unordered;
}
friend constexpr bool operator==(partial_ordering lhs, std::partial_ordering rhs) noexcept
{ return static_cast<std::partial_ordering>(lhs) == rhs; }
friend constexpr bool operator!=(partial_ordering lhs, std::partial_ordering rhs) noexcept
{ return static_cast<std::partial_ordering>(lhs) != rhs; }
friend constexpr bool operator==(std::partial_ordering lhs, partial_ordering rhs) noexcept
{ return lhs == static_cast<std::partial_ordering>(rhs); }
friend constexpr bool operator!=(std::partial_ordering lhs, partial_ordering rhs) noexcept
{ return lhs != static_cast<std::partial_ordering>(rhs); }
#endif // __cpp_lib_three_way_comparison
private:
friend class weak_ordering;
friend class strong_ordering;
constexpr explicit partial_ordering(QtPrivate::Ordering order) noexcept
: m_order(static_cast<QtPrivate::CompareUnderlyingType>(order))
{}
constexpr explicit partial_ordering(QtPrivate::Uncomparable order) noexcept
: m_order(static_cast<QtPrivate::CompareUnderlyingType>(order))
{}
QT_WARNING_PUSH
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100903
QT_WARNING_DISABLE_GCC("-Wzero-as-null-pointer-constant")
friend constexpr bool is_eq (partial_ordering o) noexcept { return o == 0; }
friend constexpr bool is_neq (partial_ordering o) noexcept { return o != 0; }
friend constexpr bool is_lt (partial_ordering o) noexcept { return o < 0; }
friend constexpr bool is_lteq(partial_ordering o) noexcept { return o <= 0; }
friend constexpr bool is_gt (partial_ordering o) noexcept { return o > 0; }
friend constexpr bool is_gteq(partial_ordering o) noexcept { return o >= 0; }
QT_WARNING_POP
// instead of the exposition only is_ordered member in [cmp.partialord],
// use a private function
constexpr bool isOrdered() const noexcept
{ return m_order != static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Uncomparable::Unordered); }
QtPrivate::CompareUnderlyingType m_order;
};
inline constexpr partial_ordering partial_ordering::less(QtPrivate::Ordering::Less);
inline constexpr partial_ordering partial_ordering::equivalent(QtPrivate::Ordering::Equivalent);
inline constexpr partial_ordering partial_ordering::greater(QtPrivate::Ordering::Greater);
inline constexpr partial_ordering partial_ordering::unordered(QtPrivate::Uncomparable::Unordered);
class weak_ordering
{
public:
static const weak_ordering less;
static const weak_ordering equivalent;
static const weak_ordering greater;
constexpr Q_IMPLICIT operator partial_ordering() const noexcept
{ return partial_ordering(static_cast<QtPrivate::Ordering>(m_order)); }
friend constexpr bool operator==(weak_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.m_order == 0; } { return lhs.m_order == 0; }
friend constexpr bool operator!=(QWeakOrdering lhs, friend constexpr bool operator!=(weak_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.m_order != 0; } { return lhs.m_order != 0; }
friend constexpr bool operator< (QWeakOrdering lhs, friend constexpr bool operator< (weak_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.m_order < 0; } { return lhs.m_order < 0; }
friend constexpr bool operator<=(QWeakOrdering lhs, friend constexpr bool operator<=(weak_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.m_order <= 0; } { return lhs.m_order <= 0; }
friend constexpr bool operator> (QWeakOrdering lhs, friend constexpr bool operator> (weak_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.m_order > 0; } { return lhs.m_order > 0; }
friend constexpr bool operator>=(QWeakOrdering lhs, friend constexpr bool operator>=(weak_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.m_order >= 0; } { return lhs.m_order >= 0; }
friend constexpr bool operator==(QtPrivate::CompareAgainstLiteralZero, friend constexpr bool operator==(QtPrivate::CompareAgainstLiteralZero,
QWeakOrdering rhs) noexcept weak_ordering rhs) noexcept
{ return 0 == rhs.m_order; } { return 0 == rhs.m_order; }
friend constexpr bool operator!=(QtPrivate::CompareAgainstLiteralZero, friend constexpr bool operator!=(QtPrivate::CompareAgainstLiteralZero,
QWeakOrdering rhs) noexcept weak_ordering rhs) noexcept
{ return 0 != rhs.m_order; } { return 0 != rhs.m_order; }
friend constexpr bool operator< (QtPrivate::CompareAgainstLiteralZero, friend constexpr bool operator< (QtPrivate::CompareAgainstLiteralZero,
QWeakOrdering rhs) noexcept weak_ordering rhs) noexcept
{ return 0 < rhs.m_order; } { return 0 < rhs.m_order; }
friend constexpr bool operator<=(QtPrivate::CompareAgainstLiteralZero, friend constexpr bool operator<=(QtPrivate::CompareAgainstLiteralZero,
QWeakOrdering rhs) noexcept weak_ordering rhs) noexcept
{ return 0 <= rhs.m_order; } { return 0 <= rhs.m_order; }
friend constexpr bool operator> (QtPrivate::CompareAgainstLiteralZero, friend constexpr bool operator> (QtPrivate::CompareAgainstLiteralZero,
QWeakOrdering rhs) noexcept weak_ordering rhs) noexcept
{ return 0 > rhs.m_order; } { return 0 > rhs.m_order; }
friend constexpr bool operator>=(QtPrivate::CompareAgainstLiteralZero, friend constexpr bool operator>=(QtPrivate::CompareAgainstLiteralZero,
QWeakOrdering rhs) noexcept weak_ordering rhs) noexcept
{ return 0 >= rhs.m_order; } { return 0 >= rhs.m_order; }
friend constexpr bool operator==(QWeakOrdering lhs, QWeakOrdering rhs) noexcept friend constexpr bool operator==(weak_ordering lhs, weak_ordering rhs) noexcept
{ return lhs.m_order == rhs.m_order; } { return lhs.m_order == rhs.m_order; }
friend constexpr bool operator!=(QWeakOrdering lhs, QWeakOrdering rhs) noexcept friend constexpr bool operator!=(weak_ordering lhs, weak_ordering rhs) noexcept
{ return lhs.m_order != rhs.m_order; } { return lhs.m_order != rhs.m_order; }
friend constexpr bool operator==(QWeakOrdering lhs, QPartialOrdering rhs) noexcept friend constexpr bool operator==(weak_ordering lhs, partial_ordering rhs) noexcept
{ return static_cast<QPartialOrdering>(lhs) == rhs; } { return static_cast<partial_ordering>(lhs) == rhs; }
friend constexpr bool operator!=(QWeakOrdering lhs, QPartialOrdering rhs) noexcept friend constexpr bool operator!=(weak_ordering lhs, partial_ordering rhs) noexcept
{ return static_cast<QPartialOrdering>(lhs) != rhs; } { return static_cast<partial_ordering>(lhs) != rhs; }
friend constexpr bool operator==(QPartialOrdering lhs, QWeakOrdering rhs) noexcept friend constexpr bool operator==(partial_ordering lhs, weak_ordering rhs) noexcept
{ return lhs == static_cast<QPartialOrdering>(rhs); } { return lhs == static_cast<partial_ordering>(rhs); }
friend constexpr bool operator!=(QPartialOrdering lhs, QWeakOrdering rhs) noexcept friend constexpr bool operator!=(partial_ordering lhs, weak_ordering rhs) noexcept
{ return lhs != static_cast<QPartialOrdering>(rhs); } { return lhs != static_cast<partial_ordering>(rhs); }
#ifdef __cpp_lib_three_way_comparison #ifdef __cpp_lib_three_way_comparison
constexpr Q_IMPLICIT QWeakOrdering(std::weak_ordering stdorder) noexcept constexpr Q_IMPLICIT weak_ordering(std::weak_ordering stdorder) noexcept
{ {
if (stdorder == std::weak_ordering::less) if (stdorder == std::weak_ordering::less)
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Less); m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Less);
@ -276,164 +413,164 @@ public:
return std::weak_ordering::equivalent; return std::weak_ordering::equivalent;
} }
friend constexpr bool operator==(QWeakOrdering lhs, std::weak_ordering rhs) noexcept friend constexpr bool operator==(weak_ordering lhs, std::weak_ordering rhs) noexcept
{ return static_cast<std::weak_ordering>(lhs) == rhs; } { return static_cast<std::weak_ordering>(lhs) == rhs; }
friend constexpr bool operator!=(QWeakOrdering lhs, std::weak_ordering rhs) noexcept friend constexpr bool operator!=(weak_ordering lhs, std::weak_ordering rhs) noexcept
{ return static_cast<std::weak_ordering>(lhs) != rhs; } { return static_cast<std::weak_ordering>(lhs) != rhs; }
friend constexpr bool operator==(QWeakOrdering lhs, std::partial_ordering rhs) noexcept friend constexpr bool operator==(weak_ordering lhs, std::partial_ordering rhs) noexcept
{ return static_cast<std::weak_ordering>(lhs) == rhs; } { return static_cast<std::weak_ordering>(lhs) == rhs; }
friend constexpr bool operator!=(QWeakOrdering lhs, std::partial_ordering rhs) noexcept friend constexpr bool operator!=(weak_ordering lhs, std::partial_ordering rhs) noexcept
{ return static_cast<std::weak_ordering>(lhs) != rhs; } { return static_cast<std::weak_ordering>(lhs) != rhs; }
friend constexpr bool operator==(QWeakOrdering lhs, std::strong_ordering rhs) noexcept friend constexpr bool operator==(weak_ordering lhs, std::strong_ordering rhs) noexcept
{ return static_cast<std::weak_ordering>(lhs) == rhs; } { return static_cast<std::weak_ordering>(lhs) == rhs; }
friend constexpr bool operator!=(QWeakOrdering lhs, std::strong_ordering rhs) noexcept friend constexpr bool operator!=(weak_ordering lhs, std::strong_ordering rhs) noexcept
{ return static_cast<std::weak_ordering>(lhs) != rhs; } { return static_cast<std::weak_ordering>(lhs) != rhs; }
friend constexpr bool operator==(std::weak_ordering lhs, QWeakOrdering rhs) noexcept friend constexpr bool operator==(std::weak_ordering lhs, weak_ordering rhs) noexcept
{ return lhs == static_cast<std::weak_ordering>(rhs); } { return lhs == static_cast<std::weak_ordering>(rhs); }
friend constexpr bool operator!=(std::weak_ordering lhs, QWeakOrdering rhs) noexcept friend constexpr bool operator!=(std::weak_ordering lhs, weak_ordering rhs) noexcept
{ return lhs != static_cast<std::weak_ordering>(rhs); } { return lhs != static_cast<std::weak_ordering>(rhs); }
friend constexpr bool operator==(std::partial_ordering lhs, QWeakOrdering rhs) noexcept friend constexpr bool operator==(std::partial_ordering lhs, weak_ordering rhs) noexcept
{ return lhs == static_cast<std::weak_ordering>(rhs); } { return lhs == static_cast<std::weak_ordering>(rhs); }
friend constexpr bool operator!=(std::partial_ordering lhs, QWeakOrdering rhs) noexcept friend constexpr bool operator!=(std::partial_ordering lhs, weak_ordering rhs) noexcept
{ return lhs != static_cast<std::weak_ordering>(rhs); } { return lhs != static_cast<std::weak_ordering>(rhs); }
friend constexpr bool operator==(std::strong_ordering lhs, QWeakOrdering rhs) noexcept friend constexpr bool operator==(std::strong_ordering lhs, weak_ordering rhs) noexcept
{ return lhs == static_cast<std::weak_ordering>(rhs); } { return lhs == static_cast<std::weak_ordering>(rhs); }
friend constexpr bool operator!=(std::strong_ordering lhs, QWeakOrdering rhs) noexcept friend constexpr bool operator!=(std::strong_ordering lhs, weak_ordering rhs) noexcept
{ return lhs != static_cast<std::weak_ordering>(rhs); } { return lhs != static_cast<std::weak_ordering>(rhs); }
#endif // __cpp_lib_three_way_comparison #endif // __cpp_lib_three_way_comparison
private: private:
friend class QStrongOrdering; friend class strong_ordering;
constexpr explicit QWeakOrdering(QtPrivate::Ordering order) noexcept constexpr explicit weak_ordering(QtPrivate::Ordering order) noexcept
: m_order(static_cast<QtPrivate::CompareUnderlyingType>(order)) : m_order(static_cast<QtPrivate::CompareUnderlyingType>(order))
{} {}
QT_WARNING_PUSH QT_WARNING_PUSH
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100903 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100903
QT_WARNING_DISABLE_GCC("-Wzero-as-null-pointer-constant") QT_WARNING_DISABLE_GCC("-Wzero-as-null-pointer-constant")
friend constexpr bool is_eq (QWeakOrdering o) noexcept { return o == 0; } friend constexpr bool is_eq (weak_ordering o) noexcept { return o == 0; }
friend constexpr bool is_neq (QWeakOrdering o) noexcept { return o != 0; } friend constexpr bool is_neq (weak_ordering o) noexcept { return o != 0; }
friend constexpr bool is_lt (QWeakOrdering o) noexcept { return o < 0; } friend constexpr bool is_lt (weak_ordering o) noexcept { return o < 0; }
friend constexpr bool is_lteq(QWeakOrdering o) noexcept { return o <= 0; } friend constexpr bool is_lteq(weak_ordering o) noexcept { return o <= 0; }
friend constexpr bool is_gt (QWeakOrdering o) noexcept { return o > 0; } friend constexpr bool is_gt (weak_ordering o) noexcept { return o > 0; }
friend constexpr bool is_gteq(QWeakOrdering o) noexcept { return o >= 0; } friend constexpr bool is_gteq(weak_ordering o) noexcept { return o >= 0; }
QT_WARNING_POP QT_WARNING_POP
QtPrivate::CompareUnderlyingType m_order; QtPrivate::CompareUnderlyingType m_order;
}; };
inline constexpr QWeakOrdering QWeakOrdering::Less(QtPrivate::Ordering::Less); inline constexpr weak_ordering weak_ordering::less(QtPrivate::Ordering::Less);
inline constexpr QWeakOrdering QWeakOrdering::Equivalent(QtPrivate::Ordering::Equivalent); inline constexpr weak_ordering weak_ordering::equivalent(QtPrivate::Ordering::Equivalent);
inline constexpr QWeakOrdering QWeakOrdering::Greater(QtPrivate::Ordering::Greater); inline constexpr weak_ordering weak_ordering::greater(QtPrivate::Ordering::Greater);
class QStrongOrdering class strong_ordering
{ {
public: public:
static const QStrongOrdering Less; static const strong_ordering less;
static const QStrongOrdering Equivalent; static const strong_ordering equivalent;
static const QStrongOrdering Equal; static const strong_ordering equal;
static const QStrongOrdering Greater; static const strong_ordering greater;
constexpr Q_IMPLICIT operator QPartialOrdering() const noexcept constexpr Q_IMPLICIT operator partial_ordering() const noexcept
{ return QPartialOrdering(static_cast<QtPrivate::Ordering>(m_order)); } { return partial_ordering(static_cast<QtPrivate::Ordering>(m_order)); }
constexpr Q_IMPLICIT operator QWeakOrdering() const noexcept constexpr Q_IMPLICIT operator weak_ordering() const noexcept
{ return QWeakOrdering(static_cast<QtPrivate::Ordering>(m_order)); } { return weak_ordering(static_cast<QtPrivate::Ordering>(m_order)); }
friend constexpr bool operator==(QStrongOrdering lhs, friend constexpr bool operator==(strong_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.m_order == 0; } { return lhs.m_order == 0; }
friend constexpr bool operator!=(QStrongOrdering lhs, friend constexpr bool operator!=(strong_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.m_order != 0; } { return lhs.m_order != 0; }
friend constexpr bool operator< (QStrongOrdering lhs, friend constexpr bool operator< (strong_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.m_order < 0; } { return lhs.m_order < 0; }
friend constexpr bool operator<=(QStrongOrdering lhs, friend constexpr bool operator<=(strong_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.m_order <= 0; } { return lhs.m_order <= 0; }
friend constexpr bool operator> (QStrongOrdering lhs, friend constexpr bool operator> (strong_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.m_order > 0; } { return lhs.m_order > 0; }
friend constexpr bool operator>=(QStrongOrdering lhs, friend constexpr bool operator>=(strong_ordering lhs,
QtPrivate::CompareAgainstLiteralZero) noexcept QtPrivate::CompareAgainstLiteralZero) noexcept
{ return lhs.m_order >= 0; } { return lhs.m_order >= 0; }
friend constexpr bool operator==(QtPrivate::CompareAgainstLiteralZero, friend constexpr bool operator==(QtPrivate::CompareAgainstLiteralZero,
QStrongOrdering rhs) noexcept strong_ordering rhs) noexcept
{ return 0 == rhs.m_order; } { return 0 == rhs.m_order; }
friend constexpr bool operator!=(QtPrivate::CompareAgainstLiteralZero, friend constexpr bool operator!=(QtPrivate::CompareAgainstLiteralZero,
QStrongOrdering rhs) noexcept strong_ordering rhs) noexcept
{ return 0 != rhs.m_order; } { return 0 != rhs.m_order; }
friend constexpr bool operator< (QtPrivate::CompareAgainstLiteralZero, friend constexpr bool operator< (QtPrivate::CompareAgainstLiteralZero,
QStrongOrdering rhs) noexcept strong_ordering rhs) noexcept
{ return 0 < rhs.m_order; } { return 0 < rhs.m_order; }
friend constexpr bool operator<=(QtPrivate::CompareAgainstLiteralZero, friend constexpr bool operator<=(QtPrivate::CompareAgainstLiteralZero,
QStrongOrdering rhs) noexcept strong_ordering rhs) noexcept
{ return 0 <= rhs.m_order; } { return 0 <= rhs.m_order; }
friend constexpr bool operator> (QtPrivate::CompareAgainstLiteralZero, friend constexpr bool operator> (QtPrivate::CompareAgainstLiteralZero,
QStrongOrdering rhs) noexcept strong_ordering rhs) noexcept
{ return 0 > rhs.m_order; } { return 0 > rhs.m_order; }
friend constexpr bool operator>=(QtPrivate::CompareAgainstLiteralZero, friend constexpr bool operator>=(QtPrivate::CompareAgainstLiteralZero,
QStrongOrdering rhs) noexcept strong_ordering rhs) noexcept
{ return 0 >= rhs.m_order; } { return 0 >= rhs.m_order; }
friend constexpr bool operator==(QStrongOrdering lhs, QStrongOrdering rhs) noexcept friend constexpr bool operator==(strong_ordering lhs, strong_ordering rhs) noexcept
{ return lhs.m_order == rhs.m_order; } { return lhs.m_order == rhs.m_order; }
friend constexpr bool operator!=(QStrongOrdering lhs, QStrongOrdering rhs) noexcept friend constexpr bool operator!=(strong_ordering lhs, strong_ordering rhs) noexcept
{ return lhs.m_order != rhs.m_order; } { return lhs.m_order != rhs.m_order; }
friend constexpr bool operator==(QStrongOrdering lhs, QPartialOrdering rhs) noexcept friend constexpr bool operator==(strong_ordering lhs, partial_ordering rhs) noexcept
{ return static_cast<QPartialOrdering>(lhs) == rhs; } { return static_cast<partial_ordering>(lhs) == rhs; }
friend constexpr bool operator!=(QStrongOrdering lhs, QPartialOrdering rhs) noexcept friend constexpr bool operator!=(strong_ordering lhs, partial_ordering rhs) noexcept
{ return static_cast<QPartialOrdering>(lhs) == rhs; } { return static_cast<partial_ordering>(lhs) == rhs; }
friend constexpr bool operator==(QPartialOrdering lhs, QStrongOrdering rhs) noexcept friend constexpr bool operator==(partial_ordering lhs, strong_ordering rhs) noexcept
{ return lhs == static_cast<QPartialOrdering>(rhs); } { return lhs == static_cast<partial_ordering>(rhs); }
friend constexpr bool operator!=(QPartialOrdering lhs, QStrongOrdering rhs) noexcept friend constexpr bool operator!=(partial_ordering lhs, strong_ordering rhs) noexcept
{ return lhs != static_cast<QPartialOrdering>(rhs); } { return lhs != static_cast<partial_ordering>(rhs); }
friend constexpr bool operator==(QStrongOrdering lhs, QWeakOrdering rhs) noexcept friend constexpr bool operator==(strong_ordering lhs, weak_ordering rhs) noexcept
{ return static_cast<QWeakOrdering>(lhs) == rhs; } { return static_cast<weak_ordering>(lhs) == rhs; }
friend constexpr bool operator!=(QStrongOrdering lhs, QWeakOrdering rhs) noexcept friend constexpr bool operator!=(strong_ordering lhs, weak_ordering rhs) noexcept
{ return static_cast<QWeakOrdering>(lhs) == rhs; } { return static_cast<weak_ordering>(lhs) == rhs; }
friend constexpr bool operator==(QWeakOrdering lhs, QStrongOrdering rhs) noexcept friend constexpr bool operator==(weak_ordering lhs, strong_ordering rhs) noexcept
{ return lhs == static_cast<QWeakOrdering>(rhs); } { return lhs == static_cast<weak_ordering>(rhs); }
friend constexpr bool operator!=(QWeakOrdering lhs, QStrongOrdering rhs) noexcept friend constexpr bool operator!=(weak_ordering lhs, strong_ordering rhs) noexcept
{ return lhs != static_cast<QWeakOrdering>(rhs); } { return lhs != static_cast<weak_ordering>(rhs); }
#ifdef __cpp_lib_three_way_comparison #ifdef __cpp_lib_three_way_comparison
constexpr Q_IMPLICIT QStrongOrdering(std::strong_ordering stdorder) noexcept constexpr Q_IMPLICIT strong_ordering(std::strong_ordering stdorder) noexcept
{ {
if (stdorder == std::strong_ordering::less) if (stdorder == std::strong_ordering::less)
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Less); m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Less);
@ -458,66 +595,68 @@ public:
return std::strong_ordering::equivalent; return std::strong_ordering::equivalent;
} }
friend constexpr bool operator==(QStrongOrdering lhs, std::strong_ordering rhs) noexcept friend constexpr bool operator==(strong_ordering lhs, std::strong_ordering rhs) noexcept
{ return static_cast<std::strong_ordering>(lhs) == rhs; } { return static_cast<std::strong_ordering>(lhs) == rhs; }
friend constexpr bool operator!=(QStrongOrdering lhs, std::strong_ordering rhs) noexcept friend constexpr bool operator!=(strong_ordering lhs, std::strong_ordering rhs) noexcept
{ return static_cast<std::strong_ordering>(lhs) != rhs; } { return static_cast<std::strong_ordering>(lhs) != rhs; }
friend constexpr bool operator==(QStrongOrdering lhs, std::partial_ordering rhs) noexcept friend constexpr bool operator==(strong_ordering lhs, std::partial_ordering rhs) noexcept
{ return static_cast<std::strong_ordering>(lhs) == rhs; } { return static_cast<std::strong_ordering>(lhs) == rhs; }
friend constexpr bool operator!=(QStrongOrdering lhs, std::partial_ordering rhs) noexcept friend constexpr bool operator!=(strong_ordering lhs, std::partial_ordering rhs) noexcept
{ return static_cast<std::strong_ordering>(lhs) != rhs; } { return static_cast<std::strong_ordering>(lhs) != rhs; }
friend constexpr bool operator==(QStrongOrdering lhs, std::weak_ordering rhs) noexcept friend constexpr bool operator==(strong_ordering lhs, std::weak_ordering rhs) noexcept
{ return static_cast<std::strong_ordering>(lhs) == rhs; } { return static_cast<std::strong_ordering>(lhs) == rhs; }
friend constexpr bool operator!=(QStrongOrdering lhs, std::weak_ordering rhs) noexcept friend constexpr bool operator!=(strong_ordering lhs, std::weak_ordering rhs) noexcept
{ return static_cast<std::strong_ordering>(lhs) != rhs; } { return static_cast<std::strong_ordering>(lhs) != rhs; }
friend constexpr bool operator==(std::strong_ordering lhs, QStrongOrdering rhs) noexcept friend constexpr bool operator==(std::strong_ordering lhs, strong_ordering rhs) noexcept
{ return lhs == static_cast<std::strong_ordering>(rhs); } { return lhs == static_cast<std::strong_ordering>(rhs); }
friend constexpr bool operator!=(std::strong_ordering lhs, QStrongOrdering rhs) noexcept friend constexpr bool operator!=(std::strong_ordering lhs, strong_ordering rhs) noexcept
{ return lhs != static_cast<std::strong_ordering>(rhs); } { return lhs != static_cast<std::strong_ordering>(rhs); }
friend constexpr bool operator==(std::partial_ordering lhs, QStrongOrdering rhs) noexcept friend constexpr bool operator==(std::partial_ordering lhs, strong_ordering rhs) noexcept
{ return lhs == static_cast<std::strong_ordering>(rhs); } { return lhs == static_cast<std::strong_ordering>(rhs); }
friend constexpr bool operator!=(std::partial_ordering lhs, QStrongOrdering rhs) noexcept friend constexpr bool operator!=(std::partial_ordering lhs, strong_ordering rhs) noexcept
{ return lhs != static_cast<std::strong_ordering>(rhs); } { return lhs != static_cast<std::strong_ordering>(rhs); }
friend constexpr bool operator==(std::weak_ordering lhs, QStrongOrdering rhs) noexcept friend constexpr bool operator==(std::weak_ordering lhs, strong_ordering rhs) noexcept
{ return lhs == static_cast<std::strong_ordering>(rhs); } { return lhs == static_cast<std::strong_ordering>(rhs); }
friend constexpr bool operator!=(std::weak_ordering lhs, QStrongOrdering rhs) noexcept friend constexpr bool operator!=(std::weak_ordering lhs, strong_ordering rhs) noexcept
{ return lhs != static_cast<std::strong_ordering>(rhs); } { return lhs != static_cast<std::strong_ordering>(rhs); }
#endif // __cpp_lib_three_way_comparison #endif // __cpp_lib_three_way_comparison
private: private:
constexpr explicit QStrongOrdering(QtPrivate::Ordering order) noexcept constexpr explicit strong_ordering(QtPrivate::Ordering order) noexcept
: m_order(static_cast<QtPrivate::CompareUnderlyingType>(order)) : m_order(static_cast<QtPrivate::CompareUnderlyingType>(order))
{} {}
QT_WARNING_PUSH QT_WARNING_PUSH
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100903 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100903
QT_WARNING_DISABLE_GCC("-Wzero-as-null-pointer-constant") QT_WARNING_DISABLE_GCC("-Wzero-as-null-pointer-constant")
friend constexpr bool is_eq (QStrongOrdering o) noexcept { return o == 0; } friend constexpr bool is_eq (strong_ordering o) noexcept { return o == 0; }
friend constexpr bool is_neq (QStrongOrdering o) noexcept { return o != 0; } friend constexpr bool is_neq (strong_ordering o) noexcept { return o != 0; }
friend constexpr bool is_lt (QStrongOrdering o) noexcept { return o < 0; } friend constexpr bool is_lt (strong_ordering o) noexcept { return o < 0; }
friend constexpr bool is_lteq(QStrongOrdering o) noexcept { return o <= 0; } friend constexpr bool is_lteq(strong_ordering o) noexcept { return o <= 0; }
friend constexpr bool is_gt (QStrongOrdering o) noexcept { return o > 0; } friend constexpr bool is_gt (strong_ordering o) noexcept { return o > 0; }
friend constexpr bool is_gteq(QStrongOrdering o) noexcept { return o >= 0; } friend constexpr bool is_gteq(strong_ordering o) noexcept { return o >= 0; }
QT_WARNING_POP QT_WARNING_POP
QtPrivate::CompareUnderlyingType m_order; QtPrivate::CompareUnderlyingType m_order;
}; };
inline constexpr QStrongOrdering QStrongOrdering::Less(QtPrivate::Ordering::Less); inline constexpr strong_ordering strong_ordering::less(QtPrivate::Ordering::Less);
inline constexpr QStrongOrdering QStrongOrdering::Equivalent(QtPrivate::Ordering::Equivalent); inline constexpr strong_ordering strong_ordering::equivalent(QtPrivate::Ordering::Equivalent);
inline constexpr QStrongOrdering QStrongOrdering::Equal(QtPrivate::Ordering::Equal); inline constexpr strong_ordering strong_ordering::equal(QtPrivate::Ordering::Equal);
inline constexpr QStrongOrdering QStrongOrdering::Greater(QtPrivate::Ordering::Greater); inline constexpr strong_ordering strong_ordering::greater(QtPrivate::Ordering::Greater);
} // namespace Qt
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -7,7 +7,7 @@
\title Comparison types overview \title Comparison types overview
\keyword three-way comparison \keyword three-way comparison
\inmodule QtCore \inmodule QtCore
\sa QStrongOrdering, QWeakOrdering, QPartialOrdering \sa Qt::strong_ordering, Qt::weak_ordering, Qt::partial_ordering
\note Qt's comparison types provide functionality equivalent to their C++20 \note Qt's comparison types provide functionality equivalent to their C++20
standard counterparts. The only reason why they exist is to make the standard counterparts. The only reason why they exist is to make the
@ -35,49 +35,49 @@
\row \row
\li \l {https://en.cppreference.com/w/cpp/utility/compare/strong_ordering} \li \l {https://en.cppreference.com/w/cpp/utility/compare/strong_ordering}
{std::strong_ordering} {std::strong_ordering}
\li QStrongOrdering \li Qt::strong_ordering
\li yes \li yes
\li yes \li yes
\li integral types, case-sensitive strings, QDate, QTime \li integral types, case-sensitive strings, QDate, QTime
\row \row
\li \l {https://en.cppreference.com/w/cpp/utility/compare/weak_ordering} \li \l {https://en.cppreference.com/w/cpp/utility/compare/weak_ordering}
{std::weak_ordering} {std::weak_ordering}
\li QWeakOrdering \li Qt::weak_ordering
\li no \li no
\li yes \li yes
\li case-insensitive strings, unordered associative containers, QDateTime \li case-insensitive strings, unordered associative containers, QDateTime
\row \row
\li \l {https://en.cppreference.com/w/cpp/utility/compare/partial_ordering} \li \l {https://en.cppreference.com/w/cpp/utility/compare/partial_ordering}
{std::partial_ordering} {std::partial_ordering}
\li QPartialOrdering \li Qt::partial_ordering
\li no \li no
\li no \li no
\li floating-point types, QOperatingSystemVersion, QVariant \li floating-point types, QOperatingSystemVersion, QVariant
\endtable \endtable
The strongest comparison type, QStrongOrdering, represents a strict total The strongest comparison type, Qt::strong_ordering, represents a strict total
order. It requires that any two elements be comparable in a way where order. It requires that any two elements be comparable in a way where
equality implies substitutability. In other words, equivalent values equality implies substitutability. In other words, equivalent values
cannot be distinguished from each other. A practical example would be the cannot be distinguished from each other. A practical example would be the
case-sensitive comparison of two strings. For instance, when comparing the case-sensitive comparison of two strings. For instance, when comparing the
values \c "Qt" and \c "Qt" the result would be \l QStrongOrdering::Equal. values \c "Qt" and \c "Qt" the result would be \l Qt::strong_ordering::equal.
Both values are indistinguishable and all deterministic operations performed Both values are indistinguishable and all deterministic operations performed
on these values would yield identical results. on these values would yield identical results.
QWeakOrdering represents a total order. While any two values still need to Qt::weak_ordering represents a total order. While any two values still need to
be comparable, equivalent values may be distinguishable. The canonical be comparable, equivalent values may be distinguishable. The canonical
example here would be the case-insensitive comparison of two strings. For example here would be the case-insensitive comparison of two strings. For
instance, when comparing the values \c "Qt" and \c "qt" both hold the same instance, when comparing the values \c "Qt" and \c "qt" both hold the same
letters but with different representations. This comparison would letters but with different representations. This comparison would
result in \l QWeakOrdering::Equivalent, but not actually \c Equal. result in \l Qt::weak_ordering::equivalent, but not actually \c Equal.
Another example would be QDateTime, which can represent a given instant in Another example would be QDateTime, which can represent a given instant in
time in terms of local time or any other time-zone, including UTC. The time in terms of local time or any other time-zone, including UTC. The
different representations are equivalent, even though their \c time() and different representations are equivalent, even though their \c time() and
sometimes \c date() may differ. sometimes \c date() may differ.
QPartialOrdering represents, as the name implies, a partial ordering. It Qt::partial_ordering represents, as the name implies, a partial ordering. It
allows for the possibility that two values may not be comparable, resulting allows for the possibility that two values may not be comparable, resulting
in an \l {QPartialOrdering::}{Unordered} state. Additionally, equivalent in an \l {Qt::partial_ordering::}{unordered} state. Additionally, equivalent
values may still be distinguishable. A practical example would be the values may still be distinguishable. A practical example would be the
comparison of two floating-point values, comparing with NaN (Not-a-Number) comparison of two floating-point values, comparing with NaN (Not-a-Number)
would yield an unordered result. Another example is the comparison of two would yield an unordered result. Another example is the comparison of two
@ -91,29 +91,29 @@
*/ */
/*! /*!
\class QStrongOrdering \class Qt::strong_ordering
\inmodule QtCore \inmodule QtCore
\brief QStrongOrdering represents a comparison where equivalent values are \brief Qt::strong_ordering represents a comparison where equivalent values are
indistinguishable. indistinguishable.
\sa QWeakOrdering, QPartialOrdering, {Comparison types overview} \sa Qt::weak_ordering, Qt::partial_ordering, {Comparison types overview}
\since 6.7 \since 6.7
A value of type QStrongOrdering is typically returned from a three-way A value of type Qt::strong_ordering is typically returned from a three-way
comparison function. Such a function compares two objects and establishes comparison function. Such a function compares two objects and establishes
that the two objects are in a strict ordering relationship; that is, the that the two objects are in a strict ordering relationship; that is, the
function establishes a well-defined total order. function establishes a well-defined total order.
The possible values of type QStrongOrdering are fully represented by the The possible values of type Qt::strong_ordering are fully represented by the
following four symbolic constants: following four symbolic constants:
\list \list
\li \c Less represents that the left operand is less than the right; \li \l less represents that the left operand is less than the right;
\li \c Equal represents that the left operand is equivalent to the right; \li \l equal represents that the left operand is equivalent to the right;
\li \c Equivalent is an alias for \c Equal; \li \l equivalent is an alias for \c Equal;
\li \c Greater represents that the left operand is greater than the right. \li \l greater represents that the left operand is greater than the right.
\endlist \endlist
QStrongOrdering is idiomatically used by comparing an instance against a Qt::strong_ordering is idiomatically used by comparing an instance against a
literal zero, for instance like this: literal zero, for instance like this:
\code \code
@ -121,10 +121,10 @@
// given a, b, c, d as objects of some type that allows for a 3-way compare, // given a, b, c, d as objects of some type that allows for a 3-way compare,
// and a compare function declared as follows: // and a compare function declared as follows:
QStrongOrdering compare(T lhs, T rhs); // defined out-of-line Qt::strong_ordering compare(T lhs, T rhs); // defined out-of-line
~~~ ~~~
QStrongOrdering result = compare(a, b); Qt::strong_ordering result = compare(a, b);
if (result < 0) { if (result < 0) {
// a is less than b // a is less than b
} }
@ -137,69 +137,69 @@
*/ */
/*! /*!
\fn QStrongOrdering::operator QPartialOrdering() const \fn Qt::strong_ordering::operator Qt::partial_ordering() const
Converts this QStrongOrdering value to a QPartialOrdering object using the Converts this Qt::strong_ordering value to a Qt::partial_ordering object using the
following rules: following rules:
\list \list
\li \l Less converts to \l {QPartialOrdering::Less}. \li \l less converts to \l {Qt::partial_ordering::less}.
\li \l Equivalent converts to \l {QPartialOrdering::Equivalent}. \li \l equivalent converts to \l {Qt::partial_ordering::equivalent}.
\li \l Equal converts to \l {QPartialOrdering::Equivalent}. \li \l equal converts to \l {Qt::partial_ordering::equivalent}.
\li \l Greater converts to \l {QPartialOrdering::Greater}. \li \l greater converts to \l {Qt::partial_ordering::greater}.
\endlist \endlist
*/ */
/*! /*!
\fn QStrongOrdering::operator QWeakOrdering() const \fn Qt::strong_ordering::operator Qt::weak_ordering() const
Converts this QStrongOrdering value to a QWeakOrdering object using the Converts this Qt::strong_ordering value to a Qt::weak_ordering object using the
following rules: following rules:
\list \list
\li \l Less converts to \l {QWeakOrdering::Less}. \li \l less converts to \l {Qt::weak_ordering::less}.
\li \l Equivalent converts to \l {QWeakOrdering::Equivalent}. \li \l equivalent converts to \l {Qt::weak_ordering::equivalent}.
\li \l Equal converts to \l {QWeakOrdering::Equivalent}. \li \l equal converts to \l {Qt::weak_ordering::equivalent}.
\li \l Greater converts to \l {QWeakOrdering::Greater}. \li \l greater converts to \l {Qt::weak_ordering::greater}.
\endlist \endlist
*/ */
/*! /*!
\fn QStrongOrdering::QStrongOrdering(std::strong_ordering stdorder) \fn Qt::strong_ordering::strong_ordering(std::strong_ordering stdorder)
Constructs a QStrongOrdering object from \a stdorder using the following rules: Constructs a Qt::strong_ordering object from \a stdorder using the following rules:
\list \list
\li std::strong_ordering::less converts to \l Less. \li std::strong_ordering::less converts to \l less.
\li std::strong_ordering::equivalent converts to \l Equivalent. \li std::strong_ordering::equivalent converts to \l equivalent.
\li std::strong_ordering::equal converts to \l Equal. \li std::strong_ordering::equal converts to \l equal.
\li std::strong_ordering::greater converts to \l Greater. \li std::strong_ordering::greater converts to \l greater.
\endlist \endlist
*/ */
/*! /*!
\fn QStrongOrdering::operator std::strong_ordering() const \fn Qt::strong_ordering::operator std::strong_ordering() const
Converts this QStrongOrdering value to a std::strong_ordering object using Converts this Qt::strong_ordering value to a std::strong_ordering object using
the following rules: the following rules:
\list \list
\li \l Less converts to std::strong_ordering::less. \li \l less converts to std::strong_ordering::less.
\li \l Equivalent converts to std::strong_ordering::equivalent. \li \l equivalent converts to std::strong_ordering::equivalent.
\li \l Equal converts to std::strong_ordering::equal. \li \l equal converts to std::strong_ordering::equal.
\li \l Greater converts to std::strong_ordering::greater. \li \l greater converts to std::strong_ordering::greater.
\endlist \endlist
*/ */
/*! /*!
\fn bool QStrongOrdering::operator==(QStrongOrdering lhs, QStrongOrdering rhs) \fn bool Qt::strong_ordering::operator==(Qt::strong_ordering lhs, Qt::strong_ordering rhs)
Returns true if \a lhs and \a rhs represent the same result; Returns true if \a lhs and \a rhs represent the same result;
otherwise, returns false. otherwise, returns false.
*/ */
/*! /*!
\fn bool QStrongOrdering::operator!=(QStrongOrdering lhs, QStrongOrdering rhs) \fn bool Qt::strong_ordering::operator!=(Qt::strong_ordering lhs, Qt::strong_ordering rhs)
Returns true if \a lhs and \a rhs represent different results; Returns true if \a lhs and \a rhs represent different results;
otherwise, returns true. otherwise, returns true.
@ -207,29 +207,29 @@
/*! /*!
\internal \internal
\relates QStrongOrdering \relates Qt::strong_ordering
\fn bool operator==(QStrongOrdering lhs, QtPrivate::CompareAgainstLiteralZero) \fn bool operator==(Qt::strong_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator!=(QStrongOrdering lhs, QtPrivate::CompareAgainstLiteralZero) \fn bool operator!=(Qt::strong_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator< (QStrongOrdering lhs, QtPrivate::CompareAgainstLiteralZero) \fn bool operator< (Qt::strong_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator<=(QStrongOrdering lhs, QtPrivate::CompareAgainstLiteralZero) \fn bool operator<=(Qt::strong_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator> (QStrongOrdering lhs, QtPrivate::CompareAgainstLiteralZero) \fn bool operator> (Qt::strong_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator>=(QStrongOrdering lhs, QtPrivate::CompareAgainstLiteralZero) \fn bool operator>=(Qt::strong_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator==(QtPrivate::CompareAgainstLiteralZero, QStrongOrdering rhs) \fn bool operator==(QtPrivate::CompareAgainstLiteralZero, Qt::strong_ordering rhs)
\fn bool operator!=(QtPrivate::CompareAgainstLiteralZero, QStrongOrdering rhs) \fn bool operator!=(QtPrivate::CompareAgainstLiteralZero, Qt::strong_ordering rhs)
\fn bool operator< (QtPrivate::CompareAgainstLiteralZero, QStrongOrdering rhs) \fn bool operator< (QtPrivate::CompareAgainstLiteralZero, Qt::strong_ordering rhs)
\fn bool operator<=(QtPrivate::CompareAgainstLiteralZero, QStrongOrdering rhs) \fn bool operator<=(QtPrivate::CompareAgainstLiteralZero, Qt::strong_ordering rhs)
\fn bool operator> (QtPrivate::CompareAgainstLiteralZero, QStrongOrdering rhs) \fn bool operator> (QtPrivate::CompareAgainstLiteralZero, Qt::strong_ordering rhs)
\fn bool operator>=(QtPrivate::CompareAgainstLiteralZero, QStrongOrdering rhs) \fn bool operator>=(QtPrivate::CompareAgainstLiteralZero, Qt::strong_ordering rhs)
*/ */
/*! /*!
\fn QStrongOrdering::is_eq (QStrongOrdering o) \fn Qt::strong_ordering::is_eq (Qt::strong_ordering o)
\fn QStrongOrdering::is_neq (QStrongOrdering o) \fn Qt::strong_ordering::is_neq (Qt::strong_ordering o)
\fn QStrongOrdering::is_lt (QStrongOrdering o) \fn Qt::strong_ordering::is_lt (Qt::strong_ordering o)
\fn QStrongOrdering::is_lteq(QStrongOrdering o) \fn Qt::strong_ordering::is_lteq(Qt::strong_ordering o)
\fn QStrongOrdering::is_gt (QStrongOrdering o) \fn Qt::strong_ordering::is_gt (Qt::strong_ordering o)
\fn QStrongOrdering::is_gteq(QStrongOrdering o) \fn Qt::strong_ordering::is_gteq(Qt::strong_ordering o)
//! [is_eq_table] //! [is_eq_table]
Converts \a o into the result of one of the six relational operators: Converts \a o into the result of one of the six relational operators:
@ -248,56 +248,56 @@
*/ */
/*! /*!
\variable QStrongOrdering::Less \variable Qt::strong_ordering::less
Represents the result of a comparison where the left operand is less Represents the result of a comparison where the left operand is less
than the right operand. than the right operand.
*/ */
/*! /*!
\variable QStrongOrdering::Equivalent \variable Qt::strong_ordering::equivalent
Represents the result of a comparison where the left operand is equal Represents the result of a comparison where the left operand is equal
to the right operand. Same as \l {QStrongOrdering::Equal}. to the right operand. Same as \l {Qt::strong_ordering::equal}.
*/ */
/*! /*!
\variable QStrongOrdering::Equal \variable Qt::strong_ordering::equal
Represents the result of a comparison where the left operand is equal Represents the result of a comparison where the left operand is equal
to the right operand. Same as \l {QStrongOrdering::Equivalent}. to the right operand. Same as \l {Qt::strong_ordering::equivalent}.
*/ */
/*! /*!
\variable QStrongOrdering::Greater \variable Qt::strong_ordering::greater
Represents the result of a comparison where the left operand is greater Represents the result of a comparison where the left operand is greater
than the right operand. than the right operand.
*/ */
/*! /*!
\class QWeakOrdering \class Qt::weak_ordering
\inmodule QtCore \inmodule QtCore
\brief QWeakOrdering represents a comparison where equivalent values are \brief Qt::weak_ordering represents a comparison where equivalent values are
still distinguishable. still distinguishable.
\sa QStrongOrdering, QPartialOrdering, {Comparison types overview} \sa Qt::strong_ordering, Qt::partial_ordering, {Comparison types overview}
\since 6.7 \since 6.7
A value of type QWeakOrdering is typically returned from a three-way A value of type Qt::weak_ordering is typically returned from a three-way
comparison function. Such a function compares two objects and establishes comparison function. Such a function compares two objects and establishes
the order of the elements relative to each other. the order of the elements relative to each other.
The possible values of type QWeakOrdering are fully represented by the The possible values of type Qt::weak_ordering are fully represented by the
following three symbolic constants: following three symbolic constants:
\list \list
\li \c Less represents that the left operand is less than the right; \li \l less represents that the left operand is less than the right;
\li \c Equivalent represents that the left operand is equivalent to the \li \l equivalent represents that the left operand is equivalent to the
right; right;
\li \c Greater represents that the left operand is greater than the right, \li \l greater represents that the left operand is greater than the right,
\endlist \endlist
QWeakOrdering is idiomatically used by comparing an instance against a Qt::weak_ordering is idiomatically used by comparing an instance against a
literal zero, for instance like this: literal zero, for instance like this:
\code \code
@ -305,10 +305,10 @@
// given a, b, c, d as objects of some type that allows for a 3-way compare, // given a, b, c, d as objects of some type that allows for a 3-way compare,
// and a compare function declared as follows: // and a compare function declared as follows:
QWeakOrdering compare(T lhs, T rhs); // defined out-of-line Qt::weak_ordering compare(T lhs, T rhs); // defined out-of-line
~~~ ~~~
QWeakOrdering result = compare(a, b); Qt::weak_ordering result = compare(a, b);
if (result < 0) { if (result < 0) {
// a is less than b // a is less than b
} }
@ -321,52 +321,52 @@
*/ */
/*! /*!
\fn QWeakOrdering::operator QPartialOrdering() const \fn Qt::weak_ordering::operator Qt::partial_ordering() const
Converts this QWeakOrdering value to a QPartialOrdering object using the Converts this Qt::weak_ordering value to a Qt::partial_ordering object using the
following rules: following rules:
\list \list
\li \l Less converts to \l {QPartialOrdering::Less}. \li \l less converts to \l {Qt::partial_ordering::less}.
\li \l Equivalent converts to \l {QPartialOrdering::Equivalent}. \li \l equivalent converts to \l {Qt::partial_ordering::equivalent}.
\li \l Greater converts to \l {QPartialOrdering::Greater}. \li \l greater converts to \l {Qt::partial_ordering::greater}.
\endlist \endlist
*/ */
/*! /*!
\fn QWeakOrdering::QWeakOrdering(std::weak_ordering stdorder) \fn Qt::weak_ordering::weak_ordering(std::weak_ordering stdorder)
Constructs a QWeakOrdering object from \a stdorder using the following rules: Constructs a Qt::weak_ordering object from \a stdorder using the following rules:
\list \list
\li std::weak_ordering::less converts to \l Less. \li std::weak_ordering::less converts to \l less.
\li std::weak_ordering::equivalent converts to \l Equivalent. \li std::weak_ordering::equivalent converts to \l equivalent.
\li std::weak_ordering::greater converts to \l Greater. \li std::weak_ordering::greater converts to \l greater.
\endlist \endlist
*/ */
/*! /*!
\fn QWeakOrdering::operator std::weak_ordering() const \fn Qt::weak_ordering::operator std::weak_ordering() const
Converts this QWeakOrdering value to a std::weak_ordering object using Converts this Qt::weak_ordering value to a std::weak_ordering object using
the following rules: the following rules:
\list \list
\li \l Less converts to std::weak_ordering::less. \li \l less converts to std::weak_ordering::less.
\li \l Equivalent converts to std::weak_ordering::equivalent. \li \l equivalent converts to std::weak_ordering::equivalent.
\li \l Greater converts to std::weak_ordering::greater. \li \l greater converts to std::weak_ordering::greater.
\endlist \endlist
*/ */
/*! /*!
\fn bool QWeakOrdering::operator==(QWeakOrdering lhs, QWeakOrdering rhs) \fn bool Qt::weak_ordering::operator==(Qt::weak_ordering lhs, Qt::weak_ordering rhs)
Return true if \a lhs and \a rhs represent the same result; Return true if \a lhs and \a rhs represent the same result;
otherwise, returns false. otherwise, returns false.
*/ */
/*! /*!
\fn bool QWeakOrdering::operator!=(QWeakOrdering lhs, QWeakOrdering rhs) \fn bool Qt::weak_ordering::operator!=(Qt::weak_ordering lhs, Qt::weak_ordering rhs)
Return true if \a lhs and \a rhs represent different results; Return true if \a lhs and \a rhs represent different results;
otherwise, returns true. otherwise, returns true.
@ -374,29 +374,29 @@
/*! /*!
\internal \internal
\relates QWeakOrdering \relates Qt::weak_ordering
\fn bool operator==(QWeakOrdering lhs, QtPrivate::CompareAgainstLiteralZero) \fn bool operator==(Qt::weak_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator!=(QWeakOrdering lhs, QtPrivate::CompareAgainstLiteralZero) \fn bool operator!=(Qt::weak_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator< (QWeakOrdering lhs, QtPrivate::CompareAgainstLiteralZero) \fn bool operator< (Qt::weak_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator<=(QWeakOrdering lhs, QtPrivate::CompareAgainstLiteralZero) \fn bool operator<=(Qt::weak_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator> (QWeakOrdering lhs, QtPrivate::CompareAgainstLiteralZero) \fn bool operator> (Qt::weak_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator>=(QWeakOrdering lhs, QtPrivate::CompareAgainstLiteralZero) \fn bool operator>=(Qt::weak_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator==(QtPrivate::CompareAgainstLiteralZero, QWeakOrdering rhs) \fn bool operator==(QtPrivate::CompareAgainstLiteralZero, Qt::weak_ordering rhs)
\fn bool operator!=(QtPrivate::CompareAgainstLiteralZero, QWeakOrdering rhs) \fn bool operator!=(QtPrivate::CompareAgainstLiteralZero, Qt::weak_ordering rhs)
\fn bool operator< (QtPrivate::CompareAgainstLiteralZero, QWeakOrdering rhs) \fn bool operator< (QtPrivate::CompareAgainstLiteralZero, Qt::weak_ordering rhs)
\fn bool operator<=(QtPrivate::CompareAgainstLiteralZero, QWeakOrdering rhs) \fn bool operator<=(QtPrivate::CompareAgainstLiteralZero, Qt::weak_ordering rhs)
\fn bool operator> (QtPrivate::CompareAgainstLiteralZero, QWeakOrdering rhs) \fn bool operator> (QtPrivate::CompareAgainstLiteralZero, Qt::weak_ordering rhs)
\fn bool operator>=(QtPrivate::CompareAgainstLiteralZero, QWeakOrdering rhs) \fn bool operator>=(QtPrivate::CompareAgainstLiteralZero, Qt::weak_ordering rhs)
*/ */
/*! /*!
\fn QWeakOrdering::is_eq (QWeakOrdering o) \fn Qt::weak_ordering::is_eq (Qt::weak_ordering o)
\fn QWeakOrdering::is_neq (QWeakOrdering o) \fn Qt::weak_ordering::is_neq (Qt::weak_ordering o)
\fn QWeakOrdering::is_lt (QWeakOrdering o) \fn Qt::weak_ordering::is_lt (Qt::weak_ordering o)
\fn QWeakOrdering::is_lteq(QWeakOrdering o) \fn Qt::weak_ordering::is_lteq(Qt::weak_ordering o)
\fn QWeakOrdering::is_gt (QWeakOrdering o) \fn Qt::weak_ordering::is_gt (Qt::weak_ordering o)
\fn QWeakOrdering::is_gteq(QWeakOrdering o) \fn Qt::weak_ordering::is_gteq(Qt::weak_ordering o)
\include qcompare.qdoc is_eq_table \include qcompare.qdoc is_eq_table
@ -404,32 +404,185 @@
*/ */
/*! /*!
\variable QWeakOrdering::Less \variable Qt::weak_ordering::less
Represents the result of a comparison where the left operand is less than Represents the result of a comparison where the left operand is less than
the right operand. the right operand.
*/ */
/*! /*!
\variable QWeakOrdering::Equivalent \variable Qt::weak_ordering::equivalent
Represents the result of a comparison where the left operand is equivalent Represents the result of a comparison where the left operand is equivalent
to the right operand. to the right operand.
*/ */
/*! /*!
\variable QWeakOrdering::Greater \variable Qt::weak_ordering::greater
Represents the result of a comparison where the left operand is greater Represents the result of a comparison where the left operand is greater
than the right operand. than the right operand.
*/ */
/*!
\class Qt::partial_ordering
\inmodule QtCore
\brief Qt::partial_ordering represents the result of a comparison that allows
for unordered results.
\sa Qt::strong_ordering, Qt::weak_ordering, {Comparison types overview}
\since 6.7
A value of type Qt::partial_ordering is typically returned from a
three-way comparison function. Such a function compares two
objects, and it may either establish that the two objects are
ordered relative to each other, or that they are not ordered. The
Qt::partial_ordering value returned from the comparison function
represents one of those possibilities.
The possible values of type Qt::partial_ordering are, in fact, fully
represented by the following four symbolic constants:
\list
\li \l less represents that the left operand is less than the right;
\li \l equivalent represents that left operand is equivalent to the right;
\li \l greater represents that the left operand is greater than the right;
\li \l unordered represents that the left operand is \e {not ordered} with
respect to the right operand.
\endlist
Qt::partial_ordering is idiomatically used by comparing an instance
against a literal zero, for instance like this:
\code
// given a, b, c, d as objects of some type that allows for a 3-way compare,
// and a compare function declared as follows:
Qt::partial_ordering compare(T lhs, T rhs); // defined out-of-line
~~~
Qt::partial_ordering result = compare(a, b);
if (result < 0) {
// a is less than b
}
if (compare(c, d) >= 0) {
// c is greater than or equal to d
}
\endcode
A Qt::partial_ordering value which represents an unordered result will
always return false when compared against literal 0.
*/
/*!
\fn Qt::partial_ordering::partial_ordering(std::partial_ordering stdorder)
Constructs a Qt::partial_ordering object from \a stdorder using the following
rules:
\list
\li std::partial_ordering::less converts to \l less.
\li std::partial_ordering::equivalent converts to \l equivalent.
\li std::partial_ordering::greater converts to \l greater.
\li std::partial_ordering::unordered converts to \l unordered
\endlist
*/
/*!
\fn Qt::partial_ordering::operator std::partial_ordering() const
Converts this Qt::partial_ordering value to a std::partial_ordering object using
the following rules:
\list
\li \l less converts to std::partial_ordering::less.
\li \l equivalent converts to std::partial_ordering::equivalent.
\li \l greater converts to std::partial_ordering::greater.
\li \l unordered converts to std::partial_ordering::unordered.
\endlist
*/
/*!
\fn bool Qt::partial_ordering::operator==(Qt::partial_ordering lhs, Qt::partial_ordering rhs)
Return true if \a lhs and \a rhs represent the same result;
otherwise, returns false.
*/
/*!
\fn bool Qt::partial_ordering::operator!=(Qt::partial_ordering lhs, Qt::partial_ordering rhs)
Return true if \a lhs and \a rhs represent different results;
otherwise, returns true.
*/
/*!
\internal
\relates Qt::partial_ordering
\fn bool operator==(Qt::partial_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator!=(Qt::partial_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator< (Qt::partial_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator<=(Qt::partial_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator> (Qt::partial_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator>=(Qt::partial_ordering lhs, QtPrivate::CompareAgainstLiteralZero)
\fn bool operator==(QtPrivate::CompareAgainstLiteralZero, Qt::partial_ordering rhs)
\fn bool operator!=(QtPrivate::CompareAgainstLiteralZero, Qt::partial_ordering rhs)
\fn bool operator< (QtPrivate::CompareAgainstLiteralZero, Qt::partial_ordering rhs)
\fn bool operator<=(QtPrivate::CompareAgainstLiteralZero, Qt::partial_ordering rhs)
\fn bool operator> (QtPrivate::CompareAgainstLiteralZero, Qt::partial_ordering rhs)
\fn bool operator>=(QtPrivate::CompareAgainstLiteralZero, Qt::partial_ordering rhs)
*/
/*!
\fn Qt::partial_ordering::is_eq (Qt::partial_ordering o)
\fn Qt::partial_ordering::is_neq (Qt::partial_ordering o)
\fn Qt::partial_ordering::is_lt (Qt::partial_ordering o)
\fn Qt::partial_ordering::is_lteq(Qt::partial_ordering o)
\fn Qt::partial_ordering::is_gt (Qt::partial_ordering o)
\fn Qt::partial_ordering::is_gteq(Qt::partial_ordering o)
\include qcompare.qdoc is_eq_table
These functions are provided for compatibility with \c{std::partial_ordering}.
*/
/*!
\variable Qt::partial_ordering::less
Represents the result of a comparison where the left operand is less than
the right operand.
*/
/*!
\variable Qt::partial_ordering::equivalent
Represents the result of a comparison where the left operand is equivalent
to the right operand.
*/
/*!
\variable Qt::partial_ordering::greater
Represents the result of a comparison where the left operand is greater
than the right operand.
*/
/*!
\variable Qt::partial_ordering::unordered
Represents the result of a comparison where the left operand is not ordered
with respect to the right operand.
*/
/*! /*!
\class QPartialOrdering \class QPartialOrdering
\inmodule QtCore \inmodule QtCore
\brief QPartialOrdering represents the result of a comparison that allows \brief QPartialOrdering represents the result of a comparison that allows
for unordered results. for unordered results.
\sa QStrongOrdering, QWeakOrdering, {Comparison types overview} \sa Qt::strong_ordering, Qt::weak_ordering, {Comparison types overview}
\since 6.0 \since 6.0
A value of type QPartialOrdering is typically returned from a A value of type QPartialOrdering is typically returned from a

View File

@ -166,8 +166,8 @@ void testEqualityOperators(LeftType lhs, RightType rhs, bool expectedEqual)
(==, !=, <, >, <=, >=) for the \a lhs operand of type \c {LeftType} and (==, !=, <, >, <=, >=) for the \a lhs operand of type \c {LeftType} and
the \a rhs operand of type \c {RightType}. the \a rhs operand of type \c {RightType}.
The \c OrderingType must be one of QPartialOrdering, QStrongOrdering, or The \c OrderingType must be one of Qt::partial_ordering,
QWeakOrdering. Qt::weak_ordering, or Qt::strong_ordering.
The \a expectedOrdering parameter provides the expected The \a expectedOrdering parameter provides the expected
relation between \a lhs and \a rhs. relation between \a lhs and \a rhs.
@ -178,7 +178,7 @@ void testEqualityOperators(LeftType lhs, RightType rhs, bool expectedEqual)
\code \code
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
QDateTime later = now.addMSec(1); QDateTime later = now.addMSec(1);
QTestPrivate::testComparisonOperators(now, later, QWeakOrdering::Less); QTestPrivate::testComparisonOperators(now, later, Qt::weak_ordering::less);
if (QTest:currentTestFailed()) if (QTest:currentTestFailed())
return; return;
\endcode \endcode
@ -186,19 +186,18 @@ void testEqualityOperators(LeftType lhs, RightType rhs, bool expectedEqual)
template <typename LeftType, typename RightType, typename OrderingType> template <typename LeftType, typename RightType, typename OrderingType>
void testAllComparisonOperators(LeftType lhs, RightType rhs, OrderingType expectedOrdering) void testAllComparisonOperators(LeftType lhs, RightType rhs, OrderingType expectedOrdering)
{ {
constexpr bool isQOrderingType = std::is_same_v<OrderingType, QPartialOrdering> constexpr bool isQOrderingType = std::is_same_v<OrderingType, Qt::partial_ordering>
|| std::is_same_v<OrderingType, QWeakOrdering> || std::is_same_v<OrderingType, Qt::weak_ordering>
|| std::is_same_v<OrderingType, QStrongOrdering>; || std::is_same_v<OrderingType, Qt::strong_ordering>;
static_assert(isQOrderingType, static_assert(isQOrderingType,
"Please provide, as the expectedOrdering parameter, a value " "Please provide, as the expectedOrdering parameter, a value "
"of one of the Q{Partial,Weak,Strong}Ordering types."); "of one of the Qt::{partial,weak,strong_ordering types.");
// We have all sorts of operator==() between Q*Ordering and std::*_ordering // We have all sorts of operator==() between Q*Ordering and std::*_ordering
// types, so we can just compare to QPartialOrdering. // types, so we can just compare to Qt::partial_ordering.
const bool expectedEqual = expectedOrdering == QPartialOrdering::Equivalent; const bool expectedEqual = expectedOrdering == Qt::partial_ordering::equivalent;
const bool expectedLess = expectedOrdering == QPartialOrdering::Less; const bool expectedLess = expectedOrdering == Qt::partial_ordering::less;
const bool expectedUnordered = expectedOrdering == QPartialOrdering::Unordered; const bool expectedUnordered = expectedOrdering == Qt::partial_ordering::unordered;
CHECK_RUNTIME_CREF(CHECK_RUNTIME_LR, lhs, rhs, ==, CHECK_RUNTIME_CREF(CHECK_RUNTIME_LR, lhs, rhs, ==,
!expectedUnordered && expectedEqual) !expectedUnordered && expectedEqual)

View File

@ -12,6 +12,7 @@ class tst_QCompare: public QObject
{ {
Q_OBJECT Q_OBJECT
private slots: private slots:
void legacyPartialOrdering();
void partialOrdering(); void partialOrdering();
void weakOrdering(); void weakOrdering();
void strongOrdering(); void strongOrdering();
@ -19,7 +20,7 @@ private slots:
void is_eq_overloads(); void is_eq_overloads();
}; };
void tst_QCompare::partialOrdering() void tst_QCompare::legacyPartialOrdering()
{ {
static_assert(QPartialOrdering::Unordered == QPartialOrdering::Unordered); static_assert(QPartialOrdering::Unordered == QPartialOrdering::Unordered);
static_assert(QPartialOrdering::Unordered != QPartialOrdering::Less); static_assert(QPartialOrdering::Unordered != QPartialOrdering::Less);
@ -129,320 +130,430 @@ void tst_QCompare::partialOrdering()
static_assert(!(0 >= QPartialOrdering::Greater)); static_assert(!(0 >= QPartialOrdering::Greater));
} }
void tst_QCompare::partialOrdering()
{
static_assert(Qt::partial_ordering::unordered == Qt::partial_ordering::unordered);
static_assert(Qt::partial_ordering::unordered != Qt::partial_ordering::less);
static_assert(Qt::partial_ordering::unordered != Qt::partial_ordering::equivalent);
static_assert(Qt::partial_ordering::unordered != Qt::partial_ordering::greater);
static_assert(Qt::partial_ordering::less != Qt::partial_ordering::unordered);
static_assert(Qt::partial_ordering::less == Qt::partial_ordering::less);
static_assert(Qt::partial_ordering::less != Qt::partial_ordering::equivalent);
static_assert(Qt::partial_ordering::less != Qt::partial_ordering::greater);
static_assert(Qt::partial_ordering::equivalent != Qt::partial_ordering::unordered);
static_assert(Qt::partial_ordering::equivalent != Qt::partial_ordering::less);
static_assert(Qt::partial_ordering::equivalent == Qt::partial_ordering::equivalent);
static_assert(Qt::partial_ordering::equivalent != Qt::partial_ordering::greater);
static_assert(Qt::partial_ordering::greater != Qt::partial_ordering::unordered);
static_assert(Qt::partial_ordering::greater != Qt::partial_ordering::less);
static_assert(Qt::partial_ordering::greater != Qt::partial_ordering::equivalent);
static_assert(Qt::partial_ordering::greater == Qt::partial_ordering::greater);
static_assert(!is_eq (Qt::partial_ordering::unordered));
static_assert(!is_neq (Qt::partial_ordering::unordered));
static_assert(!is_lt (Qt::partial_ordering::unordered));
static_assert(!is_lteq(Qt::partial_ordering::unordered));
static_assert(!is_gt (Qt::partial_ordering::unordered));
static_assert(!is_gteq(Qt::partial_ordering::unordered));
static_assert(!(Qt::partial_ordering::unordered == 0));
static_assert(!(Qt::partial_ordering::unordered != 0));
static_assert(!(Qt::partial_ordering::unordered < 0));
static_assert(!(Qt::partial_ordering::unordered <= 0));
static_assert(!(Qt::partial_ordering::unordered > 0));
static_assert(!(Qt::partial_ordering::unordered >= 0));
static_assert(!(0 == Qt::partial_ordering::unordered));
static_assert(!(0 != Qt::partial_ordering::unordered));
static_assert(!(0 < Qt::partial_ordering::unordered));
static_assert(!(0 <= Qt::partial_ordering::unordered));
static_assert(!(0 > Qt::partial_ordering::unordered));
static_assert(!(0 >= Qt::partial_ordering::unordered));
static_assert(!is_eq (Qt::partial_ordering::less));
static_assert( is_neq (Qt::partial_ordering::less));
static_assert( is_lt (Qt::partial_ordering::less));
static_assert( is_lteq(Qt::partial_ordering::less));
static_assert(!is_gt (Qt::partial_ordering::less));
static_assert(!is_gteq(Qt::partial_ordering::less));
static_assert(!(Qt::partial_ordering::less == 0));
static_assert( (Qt::partial_ordering::less != 0));
static_assert( (Qt::partial_ordering::less < 0));
static_assert( (Qt::partial_ordering::less <= 0));
static_assert(!(Qt::partial_ordering::less > 0));
static_assert(!(Qt::partial_ordering::less >= 0));
static_assert(!(0 == Qt::partial_ordering::less));
static_assert( (0 != Qt::partial_ordering::less));
static_assert(!(0 < Qt::partial_ordering::less));
static_assert(!(0 <= Qt::partial_ordering::less));
static_assert( (0 > Qt::partial_ordering::less));
static_assert( (0 >= Qt::partial_ordering::less));
static_assert( is_eq (Qt::partial_ordering::equivalent));
static_assert(!is_neq (Qt::partial_ordering::equivalent));
static_assert(!is_lt (Qt::partial_ordering::equivalent));
static_assert( is_lteq(Qt::partial_ordering::equivalent));
static_assert(!is_gt (Qt::partial_ordering::equivalent));
static_assert( is_gteq(Qt::partial_ordering::equivalent));
static_assert( (Qt::partial_ordering::equivalent == 0));
static_assert(!(Qt::partial_ordering::equivalent != 0));
static_assert(!(Qt::partial_ordering::equivalent < 0));
static_assert( (Qt::partial_ordering::equivalent <= 0));
static_assert(!(Qt::partial_ordering::equivalent > 0));
static_assert( (Qt::partial_ordering::equivalent >= 0));
static_assert( (0 == Qt::partial_ordering::equivalent));
static_assert(!(0 != Qt::partial_ordering::equivalent));
static_assert(!(0 < Qt::partial_ordering::equivalent));
static_assert( (0 <= Qt::partial_ordering::equivalent));
static_assert(!(0 > Qt::partial_ordering::equivalent));
static_assert( (0 >= Qt::partial_ordering::equivalent));
static_assert(!is_eq (Qt::partial_ordering::greater));
static_assert( is_neq (Qt::partial_ordering::greater));
static_assert(!is_lt (Qt::partial_ordering::greater));
static_assert(!is_lteq(Qt::partial_ordering::greater));
static_assert( is_gt (Qt::partial_ordering::greater));
static_assert( is_gteq(Qt::partial_ordering::greater));
static_assert(!(Qt::partial_ordering::greater == 0));
static_assert( (Qt::partial_ordering::greater != 0));
static_assert(!(Qt::partial_ordering::greater < 0));
static_assert(!(Qt::partial_ordering::greater <= 0));
static_assert( (Qt::partial_ordering::greater > 0));
static_assert( (Qt::partial_ordering::greater >= 0));
static_assert(!(0 == Qt::partial_ordering::greater));
static_assert( (0 != Qt::partial_ordering::greater));
static_assert( (0 < Qt::partial_ordering::greater));
static_assert( (0 <= Qt::partial_ordering::greater));
static_assert(!(0 > Qt::partial_ordering::greater));
static_assert(!(0 >= Qt::partial_ordering::greater));
}
void tst_QCompare::weakOrdering() void tst_QCompare::weakOrdering()
{ {
static_assert(QWeakOrdering::Less == QWeakOrdering::Less); static_assert(Qt::weak_ordering::less == Qt::weak_ordering::less);
static_assert(QWeakOrdering::Less != QWeakOrdering::Equivalent); static_assert(Qt::weak_ordering::less != Qt::weak_ordering::equivalent);
static_assert(QWeakOrdering::Less != QWeakOrdering::Greater); static_assert(Qt::weak_ordering::less != Qt::weak_ordering::greater);
static_assert(QWeakOrdering::Equivalent != QWeakOrdering::Less); static_assert(Qt::weak_ordering::equivalent != Qt::weak_ordering::less);
static_assert(QWeakOrdering::Equivalent == QWeakOrdering::Equivalent); static_assert(Qt::weak_ordering::equivalent == Qt::weak_ordering::equivalent);
static_assert(QWeakOrdering::Equivalent != QWeakOrdering::Greater); static_assert(Qt::weak_ordering::equivalent != Qt::weak_ordering::greater);
static_assert(QWeakOrdering::Greater != QWeakOrdering::Less); static_assert(Qt::weak_ordering::greater != Qt::weak_ordering::less);
static_assert(QWeakOrdering::Greater != QWeakOrdering::Equivalent); static_assert(Qt::weak_ordering::greater != Qt::weak_ordering::equivalent);
static_assert(QWeakOrdering::Greater == QWeakOrdering::Greater); static_assert(Qt::weak_ordering::greater == Qt::weak_ordering::greater);
static_assert(!is_eq (QWeakOrdering::Less)); static_assert(!is_eq (Qt::weak_ordering::less));
static_assert( is_neq (QWeakOrdering::Less)); static_assert( is_neq (Qt::weak_ordering::less));
static_assert( is_lt (QWeakOrdering::Less)); static_assert( is_lt (Qt::weak_ordering::less));
static_assert( is_lteq(QWeakOrdering::Less)); static_assert( is_lteq(Qt::weak_ordering::less));
static_assert(!is_gt (QWeakOrdering::Less)); static_assert(!is_gt (Qt::weak_ordering::less));
static_assert(!is_gteq(QWeakOrdering::Less)); static_assert(!is_gteq(Qt::weak_ordering::less));
static_assert(!(QWeakOrdering::Less == 0)); static_assert(!(Qt::weak_ordering::less == 0));
static_assert( (QWeakOrdering::Less != 0)); static_assert( (Qt::weak_ordering::less != 0));
static_assert( (QWeakOrdering::Less < 0)); static_assert( (Qt::weak_ordering::less < 0));
static_assert( (QWeakOrdering::Less <= 0)); static_assert( (Qt::weak_ordering::less <= 0));
static_assert(!(QWeakOrdering::Less > 0)); static_assert(!(Qt::weak_ordering::less > 0));
static_assert(!(QWeakOrdering::Less >= 0)); static_assert(!(Qt::weak_ordering::less >= 0));
static_assert(!(0 == QWeakOrdering::Less)); static_assert(!(0 == Qt::weak_ordering::less));
static_assert( (0 != QWeakOrdering::Less)); static_assert( (0 != Qt::weak_ordering::less));
static_assert(!(0 < QWeakOrdering::Less)); static_assert(!(0 < Qt::weak_ordering::less));
static_assert(!(0 <= QWeakOrdering::Less)); static_assert(!(0 <= Qt::weak_ordering::less));
static_assert( (0 > QWeakOrdering::Less)); static_assert( (0 > Qt::weak_ordering::less));
static_assert( (0 >= QWeakOrdering::Less)); static_assert( (0 >= Qt::weak_ordering::less));
static_assert( is_eq (QWeakOrdering::Equivalent)); static_assert( is_eq (Qt::weak_ordering::equivalent));
static_assert(!is_neq (QWeakOrdering::Equivalent)); static_assert(!is_neq (Qt::weak_ordering::equivalent));
static_assert(!is_lt (QWeakOrdering::Equivalent)); static_assert(!is_lt (Qt::weak_ordering::equivalent));
static_assert( is_lteq(QWeakOrdering::Equivalent)); static_assert( is_lteq(Qt::weak_ordering::equivalent));
static_assert(!is_gt (QWeakOrdering::Equivalent)); static_assert(!is_gt (Qt::weak_ordering::equivalent));
static_assert( is_gteq(QWeakOrdering::Equivalent)); static_assert( is_gteq(Qt::weak_ordering::equivalent));
static_assert( (QWeakOrdering::Equivalent == 0)); static_assert( (Qt::weak_ordering::equivalent == 0));
static_assert(!(QWeakOrdering::Equivalent != 0)); static_assert(!(Qt::weak_ordering::equivalent != 0));
static_assert(!(QWeakOrdering::Equivalent < 0)); static_assert(!(Qt::weak_ordering::equivalent < 0));
static_assert( (QWeakOrdering::Equivalent <= 0)); static_assert( (Qt::weak_ordering::equivalent <= 0));
static_assert(!(QWeakOrdering::Equivalent > 0)); static_assert(!(Qt::weak_ordering::equivalent > 0));
static_assert( (QWeakOrdering::Equivalent >= 0)); static_assert( (Qt::weak_ordering::equivalent >= 0));
static_assert( (0 == QWeakOrdering::Equivalent)); static_assert( (0 == Qt::weak_ordering::equivalent));
static_assert(!(0 != QWeakOrdering::Equivalent)); static_assert(!(0 != Qt::weak_ordering::equivalent));
static_assert(!(0 < QWeakOrdering::Equivalent)); static_assert(!(0 < Qt::weak_ordering::equivalent));
static_assert( (0 <= QWeakOrdering::Equivalent)); static_assert( (0 <= Qt::weak_ordering::equivalent));
static_assert(!(0 > QWeakOrdering::Equivalent)); static_assert(!(0 > Qt::weak_ordering::equivalent));
static_assert( (0 >= QWeakOrdering::Equivalent)); static_assert( (0 >= Qt::weak_ordering::equivalent));
static_assert(!is_eq (QWeakOrdering::Greater)); static_assert(!is_eq (Qt::weak_ordering::greater));
static_assert( is_neq (QWeakOrdering::Greater)); static_assert( is_neq (Qt::weak_ordering::greater));
static_assert(!is_lt (QWeakOrdering::Greater)); static_assert(!is_lt (Qt::weak_ordering::greater));
static_assert(!is_lteq(QWeakOrdering::Greater)); static_assert(!is_lteq(Qt::weak_ordering::greater));
static_assert( is_gt (QWeakOrdering::Greater)); static_assert( is_gt (Qt::weak_ordering::greater));
static_assert( is_gteq(QWeakOrdering::Greater)); static_assert( is_gteq(Qt::weak_ordering::greater));
static_assert(!(QWeakOrdering::Greater == 0)); static_assert(!(Qt::weak_ordering::greater == 0));
static_assert( (QWeakOrdering::Greater != 0)); static_assert( (Qt::weak_ordering::greater != 0));
static_assert(!(QWeakOrdering::Greater < 0)); static_assert(!(Qt::weak_ordering::greater < 0));
static_assert(!(QWeakOrdering::Greater <= 0)); static_assert(!(Qt::weak_ordering::greater <= 0));
static_assert( (QWeakOrdering::Greater > 0)); static_assert( (Qt::weak_ordering::greater > 0));
static_assert( (QWeakOrdering::Greater >= 0)); static_assert( (Qt::weak_ordering::greater >= 0));
static_assert(!(0 == QWeakOrdering::Greater)); static_assert(!(0 == Qt::weak_ordering::greater));
static_assert( (0 != QWeakOrdering::Greater)); static_assert( (0 != Qt::weak_ordering::greater));
static_assert( (0 < QWeakOrdering::Greater)); static_assert( (0 < Qt::weak_ordering::greater));
static_assert( (0 <= QWeakOrdering::Greater)); static_assert( (0 <= Qt::weak_ordering::greater));
static_assert(!(0 > QWeakOrdering::Greater)); static_assert(!(0 > Qt::weak_ordering::greater));
static_assert(!(0 >= QWeakOrdering::Greater)); static_assert(!(0 >= Qt::weak_ordering::greater));
} }
void tst_QCompare::strongOrdering() void tst_QCompare::strongOrdering()
{ {
static_assert(QStrongOrdering::Less == QStrongOrdering::Less); static_assert(Qt::strong_ordering::less == Qt::strong_ordering::less);
static_assert(QStrongOrdering::Less != QStrongOrdering::Equal); static_assert(Qt::strong_ordering::less != Qt::strong_ordering::equal);
static_assert(QStrongOrdering::Less != QStrongOrdering::Equivalent); static_assert(Qt::strong_ordering::less != Qt::strong_ordering::equivalent);
static_assert(QStrongOrdering::Less != QStrongOrdering::Greater); static_assert(Qt::strong_ordering::less != Qt::strong_ordering::greater);
static_assert(QStrongOrdering::Equal != QStrongOrdering::Less); static_assert(Qt::strong_ordering::equal != Qt::strong_ordering::less);
static_assert(QStrongOrdering::Equal == QStrongOrdering::Equal); static_assert(Qt::strong_ordering::equal == Qt::strong_ordering::equal);
static_assert(QStrongOrdering::Equal == QStrongOrdering::Equivalent); static_assert(Qt::strong_ordering::equal == Qt::strong_ordering::equivalent);
static_assert(QStrongOrdering::Equal != QStrongOrdering::Greater); static_assert(Qt::strong_ordering::equal != Qt::strong_ordering::greater);
static_assert(QStrongOrdering::Equivalent != QStrongOrdering::Less); static_assert(Qt::strong_ordering::equivalent != Qt::strong_ordering::less);
static_assert(QStrongOrdering::Equivalent == QStrongOrdering::Equal); static_assert(Qt::strong_ordering::equivalent == Qt::strong_ordering::equal);
static_assert(QStrongOrdering::Equivalent == QStrongOrdering::Equivalent); static_assert(Qt::strong_ordering::equivalent == Qt::strong_ordering::equivalent);
static_assert(QStrongOrdering::Equivalent != QStrongOrdering::Greater); static_assert(Qt::strong_ordering::equivalent != Qt::strong_ordering::greater);
static_assert(QStrongOrdering::Greater != QStrongOrdering::Less); static_assert(Qt::strong_ordering::greater != Qt::strong_ordering::less);
static_assert(QStrongOrdering::Greater != QStrongOrdering::Equal); static_assert(Qt::strong_ordering::greater != Qt::strong_ordering::equal);
static_assert(QStrongOrdering::Greater != QStrongOrdering::Equivalent); static_assert(Qt::strong_ordering::greater != Qt::strong_ordering::equivalent);
static_assert(QStrongOrdering::Greater == QStrongOrdering::Greater); static_assert(Qt::strong_ordering::greater == Qt::strong_ordering::greater);
static_assert(!is_eq (QStrongOrdering::Less)); static_assert(!is_eq (Qt::strong_ordering::less));
static_assert( is_neq (QStrongOrdering::Less)); static_assert( is_neq (Qt::strong_ordering::less));
static_assert( is_lt (QStrongOrdering::Less)); static_assert( is_lt (Qt::strong_ordering::less));
static_assert( is_lteq(QStrongOrdering::Less)); static_assert( is_lteq(Qt::strong_ordering::less));
static_assert(!is_gt (QStrongOrdering::Less)); static_assert(!is_gt (Qt::strong_ordering::less));
static_assert(!is_gteq(QStrongOrdering::Less)); static_assert(!is_gteq(Qt::strong_ordering::less));
static_assert(!(QStrongOrdering::Less == 0)); static_assert(!(Qt::strong_ordering::less == 0));
static_assert( (QStrongOrdering::Less != 0)); static_assert( (Qt::strong_ordering::less != 0));
static_assert( (QStrongOrdering::Less < 0)); static_assert( (Qt::strong_ordering::less < 0));
static_assert( (QStrongOrdering::Less <= 0)); static_assert( (Qt::strong_ordering::less <= 0));
static_assert(!(QStrongOrdering::Less > 0)); static_assert(!(Qt::strong_ordering::less > 0));
static_assert(!(QStrongOrdering::Less >= 0)); static_assert(!(Qt::strong_ordering::less >= 0));
static_assert(!(0 == QStrongOrdering::Less)); static_assert(!(0 == Qt::strong_ordering::less));
static_assert( (0 != QStrongOrdering::Less)); static_assert( (0 != Qt::strong_ordering::less));
static_assert(!(0 < QStrongOrdering::Less)); static_assert(!(0 < Qt::strong_ordering::less));
static_assert(!(0 <= QStrongOrdering::Less)); static_assert(!(0 <= Qt::strong_ordering::less));
static_assert( (0 > QStrongOrdering::Less)); static_assert( (0 > Qt::strong_ordering::less));
static_assert( (0 >= QStrongOrdering::Less)); static_assert( (0 >= Qt::strong_ordering::less));
static_assert( is_eq (QStrongOrdering::Equal)); static_assert( is_eq (Qt::strong_ordering::equal));
static_assert(!is_neq (QStrongOrdering::Equal)); static_assert(!is_neq (Qt::strong_ordering::equal));
static_assert(!is_lt (QStrongOrdering::Equal)); static_assert(!is_lt (Qt::strong_ordering::equal));
static_assert( is_lteq(QStrongOrdering::Equal)); static_assert( is_lteq(Qt::strong_ordering::equal));
static_assert(!is_gt (QStrongOrdering::Equal)); static_assert(!is_gt (Qt::strong_ordering::equal));
static_assert( is_gteq(QStrongOrdering::Equal)); static_assert( is_gteq(Qt::strong_ordering::equal));
static_assert( (QStrongOrdering::Equal == 0)); static_assert( (Qt::strong_ordering::equal == 0));
static_assert(!(QStrongOrdering::Equal != 0)); static_assert(!(Qt::strong_ordering::equal != 0));
static_assert(!(QStrongOrdering::Equal < 0)); static_assert(!(Qt::strong_ordering::equal < 0));
static_assert( (QStrongOrdering::Equal <= 0)); static_assert( (Qt::strong_ordering::equal <= 0));
static_assert(!(QStrongOrdering::Equal > 0)); static_assert(!(Qt::strong_ordering::equal > 0));
static_assert( (QStrongOrdering::Equal >= 0)); static_assert( (Qt::strong_ordering::equal >= 0));
static_assert( (0 == QStrongOrdering::Equal)); static_assert( (0 == Qt::strong_ordering::equal));
static_assert(!(0 != QStrongOrdering::Equal)); static_assert(!(0 != Qt::strong_ordering::equal));
static_assert(!(0 < QStrongOrdering::Equal)); static_assert(!(0 < Qt::strong_ordering::equal));
static_assert( (0 <= QStrongOrdering::Equal)); static_assert( (0 <= Qt::strong_ordering::equal));
static_assert(!(0 > QStrongOrdering::Equal)); static_assert(!(0 > Qt::strong_ordering::equal));
static_assert( (0 >= QStrongOrdering::Equal)); static_assert( (0 >= Qt::strong_ordering::equal));
static_assert( is_eq (QStrongOrdering::Equivalent)); static_assert( is_eq (Qt::strong_ordering::equivalent));
static_assert(!is_neq (QStrongOrdering::Equivalent)); static_assert(!is_neq (Qt::strong_ordering::equivalent));
static_assert(!is_lt (QStrongOrdering::Equivalent)); static_assert(!is_lt (Qt::strong_ordering::equivalent));
static_assert( is_lteq(QStrongOrdering::Equivalent)); static_assert( is_lteq(Qt::strong_ordering::equivalent));
static_assert(!is_gt (QStrongOrdering::Equivalent)); static_assert(!is_gt (Qt::strong_ordering::equivalent));
static_assert( is_gteq(QStrongOrdering::Equivalent)); static_assert( is_gteq(Qt::strong_ordering::equivalent));
static_assert( (QStrongOrdering::Equivalent == 0)); static_assert( (Qt::strong_ordering::equivalent == 0));
static_assert(!(QStrongOrdering::Equivalent != 0)); static_assert(!(Qt::strong_ordering::equivalent != 0));
static_assert(!(QStrongOrdering::Equivalent < 0)); static_assert(!(Qt::strong_ordering::equivalent < 0));
static_assert( (QStrongOrdering::Equivalent <= 0)); static_assert( (Qt::strong_ordering::equivalent <= 0));
static_assert(!(QStrongOrdering::Equivalent > 0)); static_assert(!(Qt::strong_ordering::equivalent > 0));
static_assert( (QStrongOrdering::Equivalent >= 0)); static_assert( (Qt::strong_ordering::equivalent >= 0));
static_assert( (0 == QStrongOrdering::Equivalent)); static_assert( (0 == Qt::strong_ordering::equivalent));
static_assert(!(0 != QStrongOrdering::Equivalent)); static_assert(!(0 != Qt::strong_ordering::equivalent));
static_assert(!(0 < QStrongOrdering::Equivalent)); static_assert(!(0 < Qt::strong_ordering::equivalent));
static_assert( (0 <= QStrongOrdering::Equivalent)); static_assert( (0 <= Qt::strong_ordering::equivalent));
static_assert(!(0 > QStrongOrdering::Equivalent)); static_assert(!(0 > Qt::strong_ordering::equivalent));
static_assert( (0 >= QStrongOrdering::Equivalent)); static_assert( (0 >= Qt::strong_ordering::equivalent));
static_assert(!is_eq (QStrongOrdering::Greater)); static_assert(!is_eq (Qt::strong_ordering::greater));
static_assert( is_neq (QStrongOrdering::Greater)); static_assert( is_neq (Qt::strong_ordering::greater));
static_assert(!is_lt (QStrongOrdering::Greater)); static_assert(!is_lt (Qt::strong_ordering::greater));
static_assert(!is_lteq(QStrongOrdering::Greater)); static_assert(!is_lteq(Qt::strong_ordering::greater));
static_assert( is_gt (QStrongOrdering::Greater)); static_assert( is_gt (Qt::strong_ordering::greater));
static_assert( is_gteq(QStrongOrdering::Greater)); static_assert( is_gteq(Qt::strong_ordering::greater));
static_assert(!(QStrongOrdering::Greater == 0)); static_assert(!(Qt::strong_ordering::greater == 0));
static_assert( (QStrongOrdering::Greater != 0)); static_assert( (Qt::strong_ordering::greater != 0));
static_assert(!(QStrongOrdering::Greater < 0)); static_assert(!(Qt::strong_ordering::greater < 0));
static_assert(!(QStrongOrdering::Greater <= 0)); static_assert(!(Qt::strong_ordering::greater <= 0));
static_assert( (QStrongOrdering::Greater > 0)); static_assert( (Qt::strong_ordering::greater > 0));
static_assert( (QStrongOrdering::Greater >= 0)); static_assert( (Qt::strong_ordering::greater >= 0));
static_assert(!(0 == QStrongOrdering::Greater)); static_assert(!(0 == Qt::strong_ordering::greater));
static_assert( (0 != QStrongOrdering::Greater)); static_assert( (0 != Qt::strong_ordering::greater));
static_assert( (0 < QStrongOrdering::Greater)); static_assert( (0 < Qt::strong_ordering::greater));
static_assert( (0 <= QStrongOrdering::Greater)); static_assert( (0 <= Qt::strong_ordering::greater));
static_assert(!(0 > QStrongOrdering::Greater)); static_assert(!(0 > Qt::strong_ordering::greater));
static_assert(!(0 >= QStrongOrdering::Greater)); static_assert(!(0 >= Qt::strong_ordering::greater));
} }
void tst_QCompare::conversions() void tst_QCompare::conversions()
{ {
// QWeakOrdering -> QPartialOrdering // Qt::weak_ordering -> Qt::partial_ordering
{ {
constexpr QPartialOrdering less = QWeakOrdering::Less; constexpr Qt::partial_ordering less = Qt::weak_ordering::less;
static_assert(less == QPartialOrdering::Less); static_assert(less == Qt::partial_ordering::less);
constexpr QPartialOrdering equivalent = QWeakOrdering::Equivalent; constexpr Qt::partial_ordering equivalent = Qt::weak_ordering::equivalent;
static_assert(equivalent == QPartialOrdering::Equivalent); static_assert(equivalent == Qt::partial_ordering::equivalent);
constexpr QPartialOrdering greater = QWeakOrdering::Greater; constexpr Qt::partial_ordering greater = Qt::weak_ordering::greater;
static_assert(greater == QPartialOrdering::Greater); static_assert(greater == Qt::partial_ordering::greater);
} }
// QStrongOrdering -> QPartialOrdering // Qt::strong_ordering -> Qt::partial_ordering
{ {
constexpr QPartialOrdering less = QStrongOrdering::Less; constexpr Qt::partial_ordering less = Qt::strong_ordering::less;
static_assert(less == QPartialOrdering::Less); static_assert(less == Qt::partial_ordering::less);
constexpr QPartialOrdering equal = QStrongOrdering::Equal; constexpr Qt::partial_ordering equal = Qt::strong_ordering::equal;
static_assert(equal == QPartialOrdering::Equivalent); static_assert(equal == Qt::partial_ordering::equivalent);
constexpr QPartialOrdering equivalent = QStrongOrdering::Equivalent; constexpr Qt::partial_ordering equivalent = Qt::strong_ordering::equivalent;
static_assert(equivalent == QPartialOrdering::Equivalent); static_assert(equivalent == Qt::partial_ordering::equivalent);
constexpr QPartialOrdering greater = QStrongOrdering::Greater; constexpr Qt::partial_ordering greater = Qt::strong_ordering::greater;
static_assert(greater == QPartialOrdering::Greater); static_assert(greater == Qt::partial_ordering::greater);
} }
// QStrongOrdering -> QWeakOrdering // Qt::strong_ordering -> Qt::weak_ordering
{ {
constexpr QWeakOrdering less = QStrongOrdering::Less; constexpr Qt::weak_ordering less = Qt::strong_ordering::less;
static_assert(less == QWeakOrdering::Less); static_assert(less == Qt::weak_ordering::less);
constexpr QWeakOrdering equal = QStrongOrdering::Equal; constexpr Qt::weak_ordering equal = Qt::strong_ordering::equal;
static_assert(equal == QWeakOrdering::Equivalent); static_assert(equal == Qt::weak_ordering::equivalent);
constexpr QWeakOrdering equivalent = QStrongOrdering::Equivalent; constexpr Qt::weak_ordering equivalent = Qt::strong_ordering::equivalent;
static_assert(equivalent == QWeakOrdering::Equivalent); static_assert(equivalent == Qt::weak_ordering::equivalent);
constexpr QWeakOrdering greater = QStrongOrdering::Greater; constexpr Qt::weak_ordering greater = Qt::strong_ordering::greater;
static_assert(greater == QWeakOrdering::Greater); static_assert(greater == Qt::weak_ordering::greater);
} }
// Mixed types // Mixed types
{ {
static_assert(QPartialOrdering::Less == QStrongOrdering::Less); static_assert(Qt::partial_ordering::less == Qt::strong_ordering::less);
static_assert(QPartialOrdering::Equivalent != QStrongOrdering::Less); static_assert(Qt::partial_ordering::equivalent != Qt::strong_ordering::less);
static_assert(QPartialOrdering::Equivalent == QStrongOrdering::Equal); static_assert(Qt::partial_ordering::equivalent == Qt::strong_ordering::equal);
static_assert(QPartialOrdering::Greater == QStrongOrdering::Greater); static_assert(Qt::partial_ordering::greater == Qt::strong_ordering::greater);
static_assert(QPartialOrdering::Less == QWeakOrdering::Less); static_assert(Qt::partial_ordering::less == Qt::weak_ordering::less);
static_assert(QPartialOrdering::Equivalent == QWeakOrdering::Equivalent); static_assert(Qt::partial_ordering::equivalent == Qt::weak_ordering::equivalent);
static_assert(QPartialOrdering::Greater == QWeakOrdering::Greater); static_assert(Qt::partial_ordering::greater == Qt::weak_ordering::greater);
static_assert(QWeakOrdering::Less == QStrongOrdering::Less); static_assert(Qt::weak_ordering::less == Qt::strong_ordering::less);
static_assert(QWeakOrdering::Equivalent != QStrongOrdering::Greater); static_assert(Qt::weak_ordering::equivalent != Qt::strong_ordering::greater);
static_assert(QWeakOrdering::Equivalent == QStrongOrdering::Equal); static_assert(Qt::weak_ordering::equivalent == Qt::strong_ordering::equal);
static_assert(QWeakOrdering::Greater == QStrongOrdering::Greater); static_assert(Qt::weak_ordering::greater == Qt::strong_ordering::greater);
static_assert(QWeakOrdering::Less == QPartialOrdering::Less); static_assert(Qt::weak_ordering::less == Qt::partial_ordering::less);
static_assert(QWeakOrdering::Equivalent == QPartialOrdering::Equivalent); static_assert(Qt::weak_ordering::equivalent == Qt::partial_ordering::equivalent);
static_assert(QWeakOrdering::Greater == QPartialOrdering::Greater); static_assert(Qt::weak_ordering::greater == Qt::partial_ordering::greater);
static_assert(QStrongOrdering::Less == QPartialOrdering::Less); static_assert(Qt::strong_ordering::less == Qt::partial_ordering::less);
static_assert(QStrongOrdering::Equivalent == QPartialOrdering::Equivalent); static_assert(Qt::strong_ordering::equivalent == Qt::partial_ordering::equivalent);
static_assert(QStrongOrdering::Equal == QPartialOrdering::Equivalent); static_assert(Qt::strong_ordering::equal == Qt::partial_ordering::equivalent);
static_assert(QStrongOrdering::Greater == QPartialOrdering::Greater); static_assert(Qt::strong_ordering::greater == Qt::partial_ordering::greater);
static_assert(QStrongOrdering::Less == QWeakOrdering::Less); static_assert(Qt::strong_ordering::less == Qt::weak_ordering::less);
static_assert(QStrongOrdering::Equivalent == QWeakOrdering::Equivalent); static_assert(Qt::strong_ordering::equivalent == Qt::weak_ordering::equivalent);
static_assert(QStrongOrdering::Equal == QWeakOrdering::Equivalent); static_assert(Qt::strong_ordering::equal == Qt::weak_ordering::equivalent);
static_assert(QStrongOrdering::Greater == QWeakOrdering::Greater); static_assert(Qt::strong_ordering::greater == Qt::weak_ordering::greater);
} }
#ifdef __cpp_lib_three_way_comparison #ifdef __cpp_lib_three_way_comparison
// QPartialOrdering <-> std::partial_ordering // Qt::partial_ordering <-> std::partial_ordering
{ {
static_assert(QPartialOrdering::Less == std::partial_ordering::less); static_assert(Qt::partial_ordering::less == std::partial_ordering::less);
static_assert(QPartialOrdering::Less != std::partial_ordering::greater); static_assert(Qt::partial_ordering::less != std::partial_ordering::greater);
static_assert(std::partial_ordering::unordered != QPartialOrdering::Equivalent); static_assert(std::partial_ordering::unordered != Qt::partial_ordering::equivalent);
static_assert(std::partial_ordering::unordered == QPartialOrdering::Unordered); static_assert(std::partial_ordering::unordered == Qt::partial_ordering::unordered);
static_assert((QPartialOrdering(std::partial_ordering::less) == static_assert((Qt::partial_ordering(std::partial_ordering::less) ==
std::partial_ordering::less)); std::partial_ordering::less));
static_assert((QPartialOrdering(std::partial_ordering::equivalent) == static_assert((Qt::partial_ordering(std::partial_ordering::equivalent) ==
std::partial_ordering::equivalent)); std::partial_ordering::equivalent));
static_assert((QPartialOrdering(std::partial_ordering::greater) == static_assert((Qt::partial_ordering(std::partial_ordering::greater) ==
std::partial_ordering::greater)); std::partial_ordering::greater));
static_assert((QPartialOrdering(std::partial_ordering::unordered) == static_assert((Qt::partial_ordering(std::partial_ordering::unordered) ==
std::partial_ordering::unordered)); std::partial_ordering::unordered));
} }
// QWeakOrdering <-> std::weak_ordering // Qt::weak_ordering <-> std::weak_ordering
{ {
static_assert(QWeakOrdering::Less == std::weak_ordering::less); static_assert(Qt::weak_ordering::less == std::weak_ordering::less);
static_assert(QWeakOrdering::Less != std::weak_ordering::equivalent); static_assert(Qt::weak_ordering::less != std::weak_ordering::equivalent);
static_assert(std::weak_ordering::greater != QWeakOrdering::Less); static_assert(std::weak_ordering::greater != Qt::weak_ordering::less);
static_assert(std::weak_ordering::equivalent == QWeakOrdering::Equivalent); static_assert(std::weak_ordering::equivalent == Qt::weak_ordering::equivalent);
static_assert((QWeakOrdering(std::weak_ordering::less) == static_assert((Qt::weak_ordering(std::weak_ordering::less) ==
std::weak_ordering::less)); std::weak_ordering::less));
static_assert((QWeakOrdering(std::weak_ordering::equivalent) == static_assert((Qt::weak_ordering(std::weak_ordering::equivalent) ==
std::weak_ordering::equivalent)); std::weak_ordering::equivalent));
static_assert((QWeakOrdering(std::weak_ordering::greater) == static_assert((Qt::weak_ordering(std::weak_ordering::greater) ==
std::weak_ordering::greater)); std::weak_ordering::greater));
} }
// QStrongOrdering <-> std::strong_ordering // Qt::strong_ordering <-> std::strong_ordering
{ {
static_assert(QStrongOrdering::Less == std::strong_ordering::less); static_assert(Qt::strong_ordering::less == std::strong_ordering::less);
static_assert(QStrongOrdering::Less != std::strong_ordering::equivalent); static_assert(Qt::strong_ordering::less != std::strong_ordering::equivalent);
static_assert(std::strong_ordering::greater != QStrongOrdering::Less); static_assert(std::strong_ordering::greater != Qt::strong_ordering::less);
static_assert(std::strong_ordering::equivalent == QStrongOrdering::Equivalent); static_assert(std::strong_ordering::equivalent == Qt::strong_ordering::equivalent);
static_assert((QStrongOrdering(std::strong_ordering::less) == static_assert((Qt::strong_ordering(std::strong_ordering::less) ==
std::strong_ordering::less)); std::strong_ordering::less));
static_assert((QStrongOrdering(std::strong_ordering::equivalent) == static_assert((Qt::strong_ordering(std::strong_ordering::equivalent) ==
std::strong_ordering::equivalent)); std::strong_ordering::equivalent));
static_assert((QStrongOrdering(std::strong_ordering::greater) == static_assert((Qt::strong_ordering(std::strong_ordering::greater) ==
std::strong_ordering::greater)); std::strong_ordering::greater));
} }
// Mixed Q*Ordering <> std::*ordering types // Mixed Qt::*_ordering <> std::*_ordering types
{ {
static_assert(QStrongOrdering::Less == std::partial_ordering::less); static_assert(Qt::strong_ordering::less == std::partial_ordering::less);
static_assert(QStrongOrdering::Less != std::partial_ordering::greater); static_assert(Qt::strong_ordering::less != std::partial_ordering::greater);
static_assert(QStrongOrdering::Equal == std::weak_ordering::equivalent); static_assert(Qt::strong_ordering::equal == std::weak_ordering::equivalent);
static_assert(QStrongOrdering::Equivalent != std::weak_ordering::less); static_assert(Qt::strong_ordering::equivalent != std::weak_ordering::less);
static_assert(QWeakOrdering::Less != std::partial_ordering::greater); static_assert(Qt::weak_ordering::less != std::partial_ordering::greater);
static_assert(QWeakOrdering::Less == std::partial_ordering::less); static_assert(Qt::weak_ordering::less == std::partial_ordering::less);
static_assert(QWeakOrdering::Equivalent == std::strong_ordering::equivalent); static_assert(Qt::weak_ordering::equivalent == std::strong_ordering::equivalent);
static_assert(QWeakOrdering::Equivalent != std::strong_ordering::less); static_assert(Qt::weak_ordering::equivalent != std::strong_ordering::less);
static_assert(QPartialOrdering::Less != std::weak_ordering::greater); static_assert(Qt::partial_ordering::less != std::weak_ordering::greater);
static_assert(QPartialOrdering::Less == std::weak_ordering::less); static_assert(Qt::partial_ordering::less == std::weak_ordering::less);
static_assert(QPartialOrdering::Equivalent == std::strong_ordering::equivalent); static_assert(Qt::partial_ordering::equivalent == std::strong_ordering::equivalent);
static_assert(QPartialOrdering::Equivalent != std::strong_ordering::less); static_assert(Qt::partial_ordering::equivalent != std::strong_ordering::less);
} }
#endif #endif

View File

@ -1052,29 +1052,29 @@ void tst_QDate::ordering_data()
{ {
QTest::addColumn<QDate>("left"); QTest::addColumn<QDate>("left");
QTest::addColumn<QDate>("right"); QTest::addColumn<QDate>("right");
QTest::addColumn<QStrongOrdering>("expectedOrdering"); QTest::addColumn<Qt::strong_ordering>("expectedOrdering");
QTest::newRow("2000-1-2_vs_2000-1-2") QTest::newRow("2000-1-2_vs_2000-1-2")
<< QDate(2000, 1, 2) << QDate(2000, 1, 2) << QStrongOrdering::Equivalent; << QDate(2000, 1, 2) << QDate(2000, 1, 2) << Qt::strong_ordering::equivalent;
QTest::newRow("2001-12-4_vs_2001-12-5") QTest::newRow("2001-12-4_vs_2001-12-5")
<< QDate(2001, 12, 4) << QDate(2001, 12, 5) << QStrongOrdering::Less; << QDate(2001, 12, 4) << QDate(2001, 12, 5) << Qt::strong_ordering::less;
QTest::newRow("2001-11-5_vs_2001-12-5") QTest::newRow("2001-11-5_vs_2001-12-5")
<< QDate(2001, 11, 5) << QDate(2001, 12, 5) << QStrongOrdering::Less; << QDate(2001, 11, 5) << QDate(2001, 12, 5) << Qt::strong_ordering::less;
QTest::newRow("2000-12-5_vs_2001-12-5") QTest::newRow("2000-12-5_vs_2001-12-5")
<< QDate(2000, 12, 5) << QDate(2001, 12, 5) << QStrongOrdering::Less; << QDate(2000, 12, 5) << QDate(2001, 12, 5) << Qt::strong_ordering::less;
QTest::newRow("2002-12-5_vs_2001-12-5") QTest::newRow("2002-12-5_vs_2001-12-5")
<< QDate(2002, 12, 5) << QDate(2001, 12, 5) << QStrongOrdering::Greater; << QDate(2002, 12, 5) << QDate(2001, 12, 5) << Qt::strong_ordering::greater;
QTest::newRow("2001-12-5_vs_2001-11-5") QTest::newRow("2001-12-5_vs_2001-11-5")
<< QDate(2001, 12, 5) << QDate(2001, 11, 5) << QStrongOrdering::Greater; << QDate(2001, 12, 5) << QDate(2001, 11, 5) << Qt::strong_ordering::greater;
QTest::newRow("2001-12-6_vs_2001-12-5") QTest::newRow("2001-12-6_vs_2001-12-5")
<< QDate(2001, 12, 6) << QDate(2001, 12, 5) << QStrongOrdering::Greater; << QDate(2001, 12, 6) << QDate(2001, 12, 5) << Qt::strong_ordering::greater;
} }
void tst_QDate::ordering() void tst_QDate::ordering()
{ {
QFETCH(QDate, left); QFETCH(QDate, left);
QFETCH(QDate, right); QFETCH(QDate, right);
QFETCH(QStrongOrdering, expectedOrdering); QFETCH(Qt::strong_ordering, expectedOrdering);
QTestPrivate::testAllComparisonOperators(left, right, expectedOrdering); QTestPrivate::testAllComparisonOperators(left, right, expectedOrdering);
} }
@ -1086,42 +1086,42 @@ void tst_QDate::ordering_chrono_types()
QDate friday(2001, 11, 30); // the 5th Friday of November 2001 QDate friday(2001, 11, 30); // the 5th Friday of November 2001
// std::chrono::year_month_day // std::chrono::year_month_day
QTestPrivate::testAllComparisonOperators(friday, year_month_day(2001y, November, 29d), QTestPrivate::testAllComparisonOperators(friday, year_month_day(2001y, November, 29d),
QStrongOrdering::Greater); Qt::strong_ordering::greater);
QTestPrivate::testAllComparisonOperators(friday, year_month_day(2001y, November, 30d), QTestPrivate::testAllComparisonOperators(friday, year_month_day(2001y, November, 30d),
QStrongOrdering::Equivalent); Qt::strong_ordering::equivalent);
QTestPrivate::testAllComparisonOperators(friday, year_month_day(2001y, December, 1d), QTestPrivate::testAllComparisonOperators(friday, year_month_day(2001y, December, 1d),
QStrongOrdering::Less); Qt::strong_ordering::less);
// std::chrono::year_month_day_last // std::chrono::year_month_day_last
QTestPrivate::testAllComparisonOperators(friday, year_month_day_last(2001y, {October / last}), QTestPrivate::testAllComparisonOperators(friday, year_month_day_last(2001y, {October / last}),
QStrongOrdering::Greater); Qt::strong_ordering::greater);
QTestPrivate::testAllComparisonOperators(friday, year_month_day_last(2001y, {November / last}), QTestPrivate::testAllComparisonOperators(friday, year_month_day_last(2001y, {November / last}),
QStrongOrdering::Equivalent); Qt::strong_ordering::equivalent);
QTestPrivate::testAllComparisonOperators(friday, year_month_day_last(2001y, {December / last}), QTestPrivate::testAllComparisonOperators(friday, year_month_day_last(2001y, {December / last}),
QStrongOrdering::Less); Qt::strong_ordering::less);
// std::chrono::year_month_weekday // std::chrono::year_month_weekday
QTestPrivate::testAllComparisonOperators(friday, QTestPrivate::testAllComparisonOperators(friday,
year_month_weekday(2001y, November, Thursday[5]), year_month_weekday(2001y, November, Thursday[5]),
QStrongOrdering::Greater); Qt::strong_ordering::greater);
QTestPrivate::testAllComparisonOperators(friday, QTestPrivate::testAllComparisonOperators(friday,
year_month_weekday(2001y, November, Friday[5]), year_month_weekday(2001y, November, Friday[5]),
QStrongOrdering::Equivalent); Qt::strong_ordering::equivalent);
QTestPrivate::testAllComparisonOperators(friday, QTestPrivate::testAllComparisonOperators(friday,
year_month_weekday(2001y, December, Saturday[1]), year_month_weekday(2001y, December, Saturday[1]),
QStrongOrdering::Less); Qt::strong_ordering::less);
// std::chrono::year_month_weekday_last // std::chrono::year_month_weekday_last
QDate thursday(2001, 11, 29); // the last Thursday of November 2001 QDate thursday(2001, 11, 29); // the last Thursday of November 2001
QTestPrivate::testAllComparisonOperators(thursday, year_month_weekday_last(2001y, November, QTestPrivate::testAllComparisonOperators(thursday, year_month_weekday_last(2001y, November,
Wednesday[last]), Wednesday[last]),
QStrongOrdering::Greater); Qt::strong_ordering::greater);
QTestPrivate::testAllComparisonOperators(thursday, year_month_weekday_last(2001y, November, QTestPrivate::testAllComparisonOperators(thursday, year_month_weekday_last(2001y, November,
Thursday[last]), Thursday[last]),
QStrongOrdering::Equivalent); Qt::strong_ordering::equivalent);
QTestPrivate::testAllComparisonOperators(thursday, year_month_weekday_last(2001y, November, QTestPrivate::testAllComparisonOperators(thursday, year_month_weekday_last(2001y, November,
Friday[last]), Friday[last]),
QStrongOrdering::Less); Qt::strong_ordering::less);
#else #else
QSKIP("This test requires C++20-level <chrono> support enabled in the standard library."); QSKIP("This test requires C++20-level <chrono> support enabled in the standard library.");
#endif // __cpp_lib_chrono >= 201907L #endif // __cpp_lib_chrono >= 201907L

View File

@ -2502,7 +2502,7 @@ void tst_QDateTime::ordering_data()
{ {
QTest::addColumn<QDateTime>("left"); QTest::addColumn<QDateTime>("left");
QTest::addColumn<QDateTime>("right"); QTest::addColumn<QDateTime>("right");
QTest::addColumn<QWeakOrdering>("expectedOrdering"); QTest::addColumn<Qt::weak_ordering>("expectedOrdering");
Q_CONSTINIT static const auto constructName = [](const QDateTime &dt) -> QByteArray { Q_CONSTINIT static const auto constructName = [](const QDateTime &dt) -> QByteArray {
if (dt.isNull()) if (dt.isNull())
@ -2513,7 +2513,7 @@ void tst_QDateTime::ordering_data()
}; };
Q_CONSTINIT static const auto generateRow = Q_CONSTINIT static const auto generateRow =
[](const QDateTime &left, const QDateTime &right, QWeakOrdering ordering) { [](const QDateTime &left, const QDateTime &right, Qt::weak_ordering ordering) {
const QByteArray leftStr = constructName(left); const QByteArray leftStr = constructName(left);
const QByteArray rightStr = constructName(right); const QByteArray rightStr = constructName(right);
QTest::addRow("%s_vs_%s", leftStr.constData(), rightStr.constData()) QTest::addRow("%s_vs_%s", leftStr.constData(), rightStr.constData())
@ -2533,25 +2533,25 @@ void tst_QDateTime::ordering_data()
epochWest1h.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(-3600)); epochWest1h.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(-3600));
QDateTime local1970(epoch.date(), epoch.time()); // Local time's epoch QDateTime local1970(epoch.date(), epoch.time()); // Local time's epoch
generateRow(june, june, QWeakOrdering::Equivalent); generateRow(june, june, Qt::weak_ordering::equivalent);
generateRow(june, juneLater, QWeakOrdering::Less); generateRow(june, juneLater, Qt::weak_ordering::less);
generateRow(june, badDay, QWeakOrdering::Greater); generateRow(june, badDay, Qt::weak_ordering::greater);
generateRow(badDay, QDateTime(), QWeakOrdering::Equivalent); generateRow(badDay, QDateTime(), Qt::weak_ordering::equivalent);
generateRow(june, QDateTime(), QWeakOrdering::Greater); generateRow(june, QDateTime(), Qt::weak_ordering::greater);
generateRow(epoch, nextDay, QWeakOrdering::Less); generateRow(epoch, nextDay, Qt::weak_ordering::less);
generateRow(epoch, prevDay, QWeakOrdering::Greater); generateRow(epoch, prevDay, Qt::weak_ordering::greater);
generateRow(epoch, epochEast1h, QWeakOrdering::Equivalent); generateRow(epoch, epochEast1h, Qt::weak_ordering::equivalent);
generateRow(epoch, epochWest1h, QWeakOrdering::Equivalent); generateRow(epoch, epochWest1h, Qt::weak_ordering::equivalent);
generateRow(epochEast1h, epochWest1h, QWeakOrdering::Equivalent); generateRow(epochEast1h, epochWest1h, Qt::weak_ordering::equivalent);
if (epochTimeType == LocalTimeIsUtc) if (epochTimeType == LocalTimeIsUtc)
generateRow(epoch, local1970, QWeakOrdering::Equivalent); generateRow(epoch, local1970, Qt::weak_ordering::equivalent);
} }
void tst_QDateTime::ordering() void tst_QDateTime::ordering()
{ {
QFETCH(QDateTime, left); QFETCH(QDateTime, left);
QFETCH(QDateTime, right); QFETCH(QDateTime, right);
QFETCH(QWeakOrdering, expectedOrdering); QFETCH(Qt::weak_ordering, expectedOrdering);
QTestPrivate::testAllComparisonOperators(left, right, expectedOrdering); QTestPrivate::testAllComparisonOperators(left, right, expectedOrdering);
} }

View File

@ -362,30 +362,30 @@ void tst_QTime::ordering_data()
{ {
QTest::addColumn<QTime>("left"); QTest::addColumn<QTime>("left");
QTest::addColumn<QTime>("right"); QTest::addColumn<QTime>("right");
QTest::addColumn<QStrongOrdering>("expectedOrdering"); QTest::addColumn<Qt::strong_ordering>("expectedOrdering");
auto generateRow = [](QTime t1, QTime t2, QStrongOrdering ordering) { auto generateRow = [](QTime t1, QTime t2, Qt::strong_ordering ordering) {
const QByteArray t1Str = t1.toString("hh:mm:ss.zz").toLatin1(); const QByteArray t1Str = t1.toString("hh:mm:ss.zz").toLatin1();
const QByteArray t2Str = t2.toString("hh:mm:ss.zz").toLatin1(); const QByteArray t2Str = t2.toString("hh:mm:ss.zz").toLatin1();
QTest::addRow("%s_vs_%s", t1Str.constData(), t2Str.constData()) << t1 << t2 << ordering; QTest::addRow("%s_vs_%s", t1Str.constData(), t2Str.constData()) << t1 << t2 << ordering;
}; };
generateRow(QTime(0, 0), QTime(0, 0), QStrongOrdering::Equivalent); generateRow(QTime(0, 0), QTime(0, 0), Qt::strong_ordering::equivalent);
generateRow(QTime(12, 34, 56, 20), QTime(12, 34, 56, 30), QStrongOrdering::Less); generateRow(QTime(12, 34, 56, 20), QTime(12, 34, 56, 30), Qt::strong_ordering::less);
generateRow(QTime(13, 34, 46, 20), QTime(13, 34, 56, 20), QStrongOrdering::Less); generateRow(QTime(13, 34, 46, 20), QTime(13, 34, 56, 20), Qt::strong_ordering::less);
generateRow(QTime(13, 24, 56, 20), QTime(13, 34, 56, 20), QStrongOrdering::Less); generateRow(QTime(13, 24, 56, 20), QTime(13, 34, 56, 20), Qt::strong_ordering::less);
generateRow(QTime(12, 34, 56, 20), QTime(13, 34, 56, 20), QStrongOrdering::Less); generateRow(QTime(12, 34, 56, 20), QTime(13, 34, 56, 20), Qt::strong_ordering::less);
generateRow(QTime(14, 34, 56, 20), QTime(13, 34, 56, 20), QStrongOrdering::Greater); generateRow(QTime(14, 34, 56, 20), QTime(13, 34, 56, 20), Qt::strong_ordering::greater);
generateRow(QTime(13, 44, 56, 20), QTime(13, 34, 56, 20), QStrongOrdering::Greater); generateRow(QTime(13, 44, 56, 20), QTime(13, 34, 56, 20), Qt::strong_ordering::greater);
generateRow(QTime(13, 34, 56, 20), QTime(13, 34, 46, 20), QStrongOrdering::Greater); generateRow(QTime(13, 34, 56, 20), QTime(13, 34, 46, 20), Qt::strong_ordering::greater);
generateRow(QTime(13, 34, 56, 30), QTime(13, 34, 56, 20), QStrongOrdering::Greater); generateRow(QTime(13, 34, 56, 30), QTime(13, 34, 56, 20), Qt::strong_ordering::greater);
} }
void tst_QTime::ordering() void tst_QTime::ordering()
{ {
QFETCH(QTime, left); QFETCH(QTime, left);
QFETCH(QTime, right); QFETCH(QTime, right);
QFETCH(QStrongOrdering, expectedOrdering); QFETCH(Qt::strong_ordering, expectedOrdering);
QTestPrivate::testAllComparisonOperators(left, right, expectedOrdering); QTestPrivate::testAllComparisonOperators(left, right, expectedOrdering);
} }