summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qcompare.h57
-rw-r--r--src/corelib/global/qcomparehelpers.h5
2 files changed, 62 insertions, 0 deletions
diff --git a/src/corelib/global/qcompare.h b/src/corelib/global/qcompare.h
index 35123dcb36..9e67bdaa94 100644
--- a/src/corelib/global/qcompare.h
+++ b/src/corelib/global/qcompare.h
@@ -47,6 +47,19 @@ enum class Uncomparable : CompareUnderlyingType
} // namespace QtPrivate
+namespace QtOrderingPrivate {
+
+template <typename O>
+constexpr O reversed(O o) noexcept
+{
+ // https://eel.is/c++draft/cmp.partialord#5
+ return is_lt(o) ? O::greater :
+ is_gt(o) ? O::less :
+ /*else*/ o ;
+}
+
+} // namespace QtOrderingPrivate
+
namespace Qt {
class partial_ordering
@@ -107,6 +120,17 @@ public:
{ return rhs.isOrdered() && 0 >= rhs.m_order; }
+#ifdef __cpp_lib_three_way_comparison
+ friend constexpr std::partial_ordering
+ operator<=>(partial_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
+ { return lhs; } // https://eel.is/c++draft/cmp.partialord#4
+
+ friend constexpr std::partial_ordering
+ operator<=>(QtPrivate::CompareAgainstLiteralZero, partial_ordering rhs) noexcept
+ { return QtOrderingPrivate::reversed(rhs); }
+#endif // __cpp_lib_three_way_comparison
+
+
friend constexpr bool operator==(partial_ordering lhs, partial_ordering rhs) noexcept
{ return lhs.m_order == rhs.m_order; }
@@ -253,6 +277,17 @@ public:
{ return 0 >= rhs.m_order; }
+#ifdef __cpp_lib_three_way_comparison
+ friend constexpr std::weak_ordering
+ operator<=>(weak_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
+ { return lhs; } // https://eel.is/c++draft/cmp.weakord#5
+
+ friend constexpr std::weak_ordering
+ operator<=>(QtPrivate::CompareAgainstLiteralZero, weak_ordering rhs) noexcept
+ { return QtOrderingPrivate::reversed(rhs); }
+#endif // __cpp_lib_three_way_comparison
+
+
friend constexpr bool operator==(weak_ordering lhs, weak_ordering rhs) noexcept
{ return lhs.m_order == rhs.m_order; }
@@ -425,6 +460,17 @@ public:
{ return 0 >= rhs.m_order; }
+#ifdef __cpp_lib_three_way_comparison
+ friend constexpr std::strong_ordering
+ operator<=>(strong_ordering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
+ { return lhs; } // https://eel.is/c++draft/cmp.strongord#6
+
+ friend constexpr std::strong_ordering
+ operator<=>(QtPrivate::CompareAgainstLiteralZero, strong_ordering rhs) noexcept
+ { return QtOrderingPrivate::reversed(rhs); }
+#endif // __cpp_lib_three_way_comparison
+
+
friend constexpr bool operator==(strong_ordering lhs, strong_ordering rhs) noexcept
{ return lhs.m_order == rhs.m_order; }
@@ -699,6 +745,17 @@ public:
{ return rhs.isOrdered() && 0 >= rhs.m_order; }
+#ifdef __cpp_lib_three_way_comparison
+ friend constexpr std::partial_ordering
+ operator<=>(QPartialOrdering lhs, QtPrivate::CompareAgainstLiteralZero) noexcept
+ { return lhs; } // https://eel.is/c++draft/cmp.partialord#4
+
+ friend constexpr std::partial_ordering
+ operator<=>(QtPrivate::CompareAgainstLiteralZero, QPartialOrdering rhs) noexcept
+ { return QtOrderingPrivate::reversed(rhs); }
+#endif // __cpp_lib_three_way_comparison
+
+
friend constexpr bool operator==(QPartialOrdering lhs, QPartialOrdering rhs) noexcept
{ return lhs.m_order == rhs.m_order; }
diff --git a/src/corelib/global/qcomparehelpers.h b/src/corelib/global/qcomparehelpers.h
index d7e007b8b0..0394703e17 100644
--- a/src/corelib/global/qcomparehelpers.h
+++ b/src/corelib/global/qcomparehelpers.h
@@ -27,6 +27,8 @@
QT_BEGIN_NAMESPACE
+class QPartialOrdering;
+
namespace QtOrderingPrivate {
#ifdef __cpp_lib_three_way_comparison
@@ -44,6 +46,9 @@ QT_STD_MAP(weak)
QT_STD_MAP(strong)
#undef QT_STD_MAP
+template <> struct StdOrdering<QPartialOrdering> : q20::type_identity<std::partial_ordering> {};
+template <> struct QtOrdering<QPartialOrdering> : q20::type_identity< Qt::partial_ordering> {};
+
template <typename In> constexpr auto to_std(In in) noexcept
-> typename QtOrderingPrivate::StdOrdering<In>::type
{ return in; }