summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/global/qcomparehelpers.h29
-rw-r--r--tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp14
2 files changed, 31 insertions, 12 deletions
diff --git a/src/corelib/global/qcomparehelpers.h b/src/corelib/global/qcomparehelpers.h
index d0991e91b3..9c9da2c7d9 100644
--- a/src/corelib/global/qcomparehelpers.h
+++ b/src/corelib/global/qcomparehelpers.h
@@ -21,11 +21,40 @@
#ifdef __cpp_lib_three_way_comparison
#include <compare>
#endif
+#include <QtCore/q20type_traits.h>
#include <functional> // std::less
QT_BEGIN_NAMESPACE
+namespace QtOrderingPrivate {
+#ifdef __cpp_lib_three_way_comparison
+
+template <typename QtOrdering> struct StdOrdering;
+template <typename StdOrdering> struct QtOrdering;
+
+#define QT_STD_MAP(x) \
+ template <> struct StdOrdering< Qt::x##_ordering> : q20::type_identity<std::x##_ordering> {};\
+ template <> struct StdOrdering<std::x##_ordering> : q20::type_identity<std::x##_ordering> {};\
+ template <> struct QtOrdering<std::x##_ordering> : q20::type_identity< Qt::x##_ordering> {};\
+ template <> struct QtOrdering< Qt::x##_ordering> : q20::type_identity< Qt::x##_ordering> {};\
+ /* end */
+QT_STD_MAP(partial)
+QT_STD_MAP(weak)
+QT_STD_MAP(strong)
+#undef QT_STD_MAP
+
+template <typename In> constexpr auto to_std(In in) noexcept
+ -> typename QtOrderingPrivate::StdOrdering<In>::type
+{ return in; }
+
+template <typename In> constexpr auto to_Qt(In in) noexcept
+ -> typename QtOrderingPrivate::QtOrdering<In>::type
+{ return in; }
+
+#endif // __cpp_lib_three_way_comparison
+} // namespace QtOrderingPrivate
+
/*
For all the macros these parameter names are used:
* LeftType - the type of the left operand of the comparison
diff --git a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp
index 995418780a..0dfe4ab5de 100644
--- a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp
+++ b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp
@@ -206,18 +206,8 @@ void tst_QCompareHelpers::compareImpl()
return;
#ifdef __cpp_lib_three_way_comparison
// Also check std types.
-
- // if Ordering == Qt::strong_ordering -> std::strong_ordering
- // else if Ordering == Qt::weak_ordering -> std::weak_ordering
- // else std::partial_ordering
- using StdType = std::conditional_t<
- std::is_same_v<OrderingType, Qt::strong_ordering>,
- std::strong_ordering,
- std::conditional_t<std::is_same_v<OrderingType, Qt::weak_ordering>,
- std::weak_ordering,
- std::partial_ordering>>;
-
- QTestPrivate::testAllComparisonOperators(lhs, rhs, static_cast<StdType>(expectedOrdering));
+ QTestPrivate::testAllComparisonOperators(lhs, rhs,
+ QtOrderingPrivate::to_std(expectedOrdering));
if (QTest::currentTestFailed())
return;
#endif // __cpp_lib_three_way_comparison