Qt ordering types: unify the form of the implicit conversion operators
The case statements I used when de-pessimising these functions were pretty long, bumping against line-length limitations and annoying the reader with overly long repetitive type names. Add aliases to fix both issues, and also apply the form to QPartialOrdering's operator std::partial_ordering for consistency. I was kinda hoping that this would allow to DRY away some of the repetition with macros, but it didn't work out in the end. It's still a lot more pleasant to the eye, so don't let the experiment be for nothing. Amends 9c03935c9a22f3f6baa602ec0ea7ce91f4a842f0. Change-Id: I9786ae5c7be0b8fb30e4df219f1c65b2e8589904 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
parent
a0ae96e3e7
commit
1576d70e44
@ -132,13 +132,16 @@ public:
|
||||
#ifdef __cpp_lib_bit_cast
|
||||
return std::bit_cast<std::partial_ordering>(*this);
|
||||
#else
|
||||
using O = QtPrivate::Ordering;
|
||||
using U = QtPrivate::Uncomparable;
|
||||
using R = std::partial_ordering;
|
||||
switch (m_order) {
|
||||
case qToUnderlying(QtPrivate::Ordering::Less): return std::partial_ordering::less;
|
||||
case qToUnderlying(QtPrivate::Ordering::Greater): return std::partial_ordering::greater;
|
||||
case qToUnderlying(QtPrivate::Ordering::Equivalent): return std::partial_ordering::equivalent;
|
||||
case qToUnderlying(QtPrivate::Uncomparable::Unordered): return std::partial_ordering::unordered;
|
||||
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;
|
||||
}
|
||||
Q_UNREACHABLE_RETURN(std::partial_ordering::unordered);
|
||||
Q_UNREACHABLE_RETURN(R::unordered);
|
||||
#endif // __cpp_lib_bit_cast
|
||||
}
|
||||
|
||||
@ -285,12 +288,14 @@ public:
|
||||
#ifdef __cpp_lib_bit_cast
|
||||
return std::bit_cast<std::weak_ordering>(*this);
|
||||
#else
|
||||
using O = QtPrivate::Ordering;
|
||||
using R = std::weak_ordering;
|
||||
switch (m_order) {
|
||||
case qToUnderlying(QtPrivate::Ordering::Less): return std::weak_ordering::less;
|
||||
case qToUnderlying(QtPrivate::Ordering::Greater): return std::weak_ordering::greater;
|
||||
case qToUnderlying(QtPrivate::Ordering::Equivalent): return std::weak_ordering::equivalent;
|
||||
case qToUnderlying(O::Less): return R::less;
|
||||
case qToUnderlying(O::Greater): return R::greater;
|
||||
case qToUnderlying(O::Equivalent): return R::equivalent;
|
||||
}
|
||||
Q_UNREACHABLE_RETURN(std::weak_ordering::equivalent);
|
||||
Q_UNREACHABLE_RETURN(R::equivalent);
|
||||
#endif // __cpp_lib_bit_cast
|
||||
}
|
||||
|
||||
@ -469,12 +474,14 @@ public:
|
||||
#ifdef __cpp_lib_bit_cast
|
||||
return std::bit_cast<std::strong_ordering>(*this);
|
||||
#else
|
||||
using O = QtPrivate::Ordering;
|
||||
using R = std::strong_ordering;
|
||||
switch (m_order) {
|
||||
case qToUnderlying(QtPrivate::Ordering::Less): return std::strong_ordering::less;
|
||||
case qToUnderlying(QtPrivate::Ordering::Greater): return std::strong_ordering::greater;
|
||||
case qToUnderlying(QtPrivate::Ordering::Equal): return std::strong_ordering::equal;
|
||||
case qToUnderlying(O::Less): return R::less;
|
||||
case qToUnderlying(O::Greater): return R::greater;
|
||||
case qToUnderlying(O::Equal): return R::equal;
|
||||
}
|
||||
Q_UNREACHABLE_RETURN(std::strong_ordering::equal);
|
||||
Q_UNREACHABLE_RETURN(R::equal);
|
||||
#endif // __cpp_lib_bit_cast
|
||||
}
|
||||
|
||||
@ -714,15 +721,16 @@ public:
|
||||
|
||||
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::LegacyUncomparable>(m_order) == QtPrivate::LegacyUncomparable::Unordered)
|
||||
return std::partial_ordering::unordered;
|
||||
return std::partial_ordering::unordered;
|
||||
using O = QtPrivate::Ordering;
|
||||
using U = QtPrivate::LegacyUncomparable;
|
||||
using R = std::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;
|
||||
}
|
||||
Q_UNREACHABLE_RETURN(R::unordered);
|
||||
}
|
||||
|
||||
friend constexpr bool operator==(QPartialOrdering lhs, std::partial_ordering rhs) noexcept
|
||||
|
Loading…
x
Reference in New Issue
Block a user