tst_QCompareHelpers: extract Qt/std-mapping into public header
We'll need this elsehere, too. Change-Id: I91a35a23dd201f7867898cee5b4d6743883f71fc Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>bb10
parent
82a40f084b
commit
ee623402df
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue