QPartialOrdering: add missing conversions to/from Qt::_ordering types
Since QPartialOrdering is supposed to be a drop-in-replacement for Qt::partial_ordering, it need to have the same conversions from Qt::_ordering types that Qt::partial_ordering has. Fix by adding the necessary conversion and relational operators and conversion constructors. Change-Id: Ib8e78c850b43c8bcb3bb15c5f7d25be9d0da7339 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
parent
1576d70e44
commit
07ed8acdf9
@ -700,6 +700,54 @@ public:
|
|||||||
friend constexpr bool operator!=(QPartialOrdering lhs, QPartialOrdering rhs) noexcept
|
friend constexpr bool operator!=(QPartialOrdering lhs, QPartialOrdering rhs) noexcept
|
||||||
{ return lhs.m_order != rhs.m_order; }
|
{ return lhs.m_order != rhs.m_order; }
|
||||||
|
|
||||||
|
constexpr Q_IMPLICIT QPartialOrdering(Qt::partial_ordering order) noexcept
|
||||||
|
: m_order{} // == equivalent
|
||||||
|
{
|
||||||
|
if (order == Qt::partial_ordering::less)
|
||||||
|
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Less);
|
||||||
|
else if (order == Qt::partial_ordering::greater)
|
||||||
|
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::Ordering::Greater);
|
||||||
|
else if (order == Qt::partial_ordering::unordered)
|
||||||
|
m_order = static_cast<QtPrivate::CompareUnderlyingType>(QtPrivate::LegacyUncomparable::Unordered);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Q_IMPLICIT QPartialOrdering(Qt::weak_ordering stdorder) noexcept
|
||||||
|
: QPartialOrdering(Qt::partial_ordering{stdorder}) {}
|
||||||
|
|
||||||
|
constexpr Q_IMPLICIT QPartialOrdering(Qt::strong_ordering stdorder) noexcept
|
||||||
|
: QPartialOrdering(Qt::partial_ordering{stdorder}) {}
|
||||||
|
|
||||||
|
constexpr Q_IMPLICIT operator Qt::partial_ordering() const noexcept
|
||||||
|
{
|
||||||
|
using O = QtPrivate::Ordering;
|
||||||
|
using U = QtPrivate::LegacyUncomparable;
|
||||||
|
using R = Qt::partial_ordering;
|
||||||
|
switch (m_order) {
|
||||||
|
case qToUnderlying(O::Less): return R::less;
|
||||||
|
case qToUnderlying(O::Greater): return R::greater;
|
||||||
|
case qToUnderlying(O::Equivalent): return R::equivalent;
|
||||||
|
case qToUnderlying(U::Unordered): return R::unordered;
|
||||||
|
}
|
||||||
|
// GCC 8.x does not treat __builtin_unreachable() as constexpr
|
||||||
|
#if !defined(Q_CC_GNU_ONLY) || (Q_CC_GNU >= 900)
|
||||||
|
// NOLINTNEXTLINE(qt-use-unreachable-return): Triggers on Clang, breaking GCC 8
|
||||||
|
Q_UNREACHABLE();
|
||||||
|
#endif
|
||||||
|
return R::unordered;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend constexpr bool operator==(QPartialOrdering lhs, Qt::partial_ordering rhs) noexcept
|
||||||
|
{ Qt::partial_ordering qt = lhs; return qt == rhs; }
|
||||||
|
|
||||||
|
friend constexpr bool operator!=(QPartialOrdering lhs, Qt::partial_ordering rhs) noexcept
|
||||||
|
{ Qt::partial_ordering qt = lhs; return qt != rhs; }
|
||||||
|
|
||||||
|
friend constexpr bool operator==(Qt::partial_ordering lhs, QPartialOrdering rhs) noexcept
|
||||||
|
{ Qt::partial_ordering qt = rhs; return lhs == qt; }
|
||||||
|
|
||||||
|
friend constexpr bool operator!=(Qt::partial_ordering lhs, QPartialOrdering rhs) noexcept
|
||||||
|
{ Qt::partial_ordering qt = rhs; return lhs != qt; }
|
||||||
|
|
||||||
#ifdef __cpp_lib_three_way_comparison
|
#ifdef __cpp_lib_three_way_comparison
|
||||||
constexpr Q_IMPLICIT QPartialOrdering(std::partial_ordering stdorder) noexcept
|
constexpr Q_IMPLICIT QPartialOrdering(std::partial_ordering stdorder) noexcept
|
||||||
{
|
{
|
||||||
|
@ -148,6 +148,7 @@ void tst_QCompare::legacyConversions()
|
|||||||
CHECK_CONVERTS(NS ::strong_ordering, QPartialOrdering); \
|
CHECK_CONVERTS(NS ::strong_ordering, QPartialOrdering); \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
|
CHECK_ALL(Qt);
|
||||||
#ifdef __cpp_lib_three_way_comparison
|
#ifdef __cpp_lib_three_way_comparison
|
||||||
CHECK_ALL(std);
|
CHECK_ALL(std);
|
||||||
#endif // __cpp_lib_three_way_comparison
|
#endif // __cpp_lib_three_way_comparison
|
||||||
|
Loading…
x
Reference in New Issue
Block a user