refactor(miscellaneous): replace TSynthThreeWay with the function version
This commit is contained in:
parent
38902eb779
commit
7aadebba70
@ -205,27 +205,18 @@ void TestCompare()
|
|||||||
always_check((TIsSame<TCompareThreeWayResult<FTestWeakOrdering >::Type, weak_ordering >::Value));
|
always_check((TIsSame<TCompareThreeWayResult<FTestWeakOrdering >::Type, weak_ordering >::Value));
|
||||||
always_check((TIsSame<TCompareThreeWayResult<FTestStrongOrdering >::Type, strong_ordering >::Value));
|
always_check((TIsSame<TCompareThreeWayResult<FTestStrongOrdering >::Type, strong_ordering >::Value));
|
||||||
|
|
||||||
always_check((TCompareThreeWay<int32>()(0, 0) == strong_ordering::equal));
|
always_check((SynthThreeWayCompare(0, 0) == strong_ordering::equal));
|
||||||
always_check((TCompareThreeWay<void>() (0, 0.0) == strong_ordering::equal));
|
always_check((SynthThreeWayCompare(0, 0.0) == strong_ordering::equal));
|
||||||
|
|
||||||
|
always_check(SynthThreeWayCompare(FTestPartialOrdering(-1), FTestPartialOrdering( 0)) == partial_ordering::less);
|
||||||
|
always_check(SynthThreeWayCompare(FTestPartialOrdering( 0), FTestPartialOrdering( 0)) == partial_ordering::equivalent);
|
||||||
|
always_check(SynthThreeWayCompare(FTestPartialOrdering( 0), FTestPartialOrdering(-1)) == partial_ordering::greater);
|
||||||
|
|
||||||
always_check(TSynthThreeWay{}(FTestPartialOrdering(-1), FTestPartialOrdering( 0)) == partial_ordering::less);
|
always_check(SynthThreeWayCompare(FTestPartialOrdering( 0, true), FTestPartialOrdering( 0, false)) == partial_ordering::unordered);
|
||||||
always_check(TSynthThreeWay{}(FTestPartialOrdering( 0), FTestPartialOrdering( 0)) == partial_ordering::equivalent);
|
|
||||||
always_check(TSynthThreeWay{}(FTestPartialOrdering( 0), FTestPartialOrdering(-1)) == partial_ordering::greater);
|
|
||||||
|
|
||||||
always_check(TSynthThreeWay{}(FTestPartialOrdering( 0, true), FTestPartialOrdering( 0, false)) == partial_ordering::unordered);
|
|
||||||
|
|
||||||
always_check(TSynthThreeWay{}(FTestSynth(-1), FTestSynth( 0)) == weak_ordering::less);
|
|
||||||
always_check(TSynthThreeWay{}(FTestSynth( 0), FTestSynth( 0)) == weak_ordering::equivalent);
|
|
||||||
always_check(TSynthThreeWay{}(FTestSynth( 0), FTestSynth(-1)) == weak_ordering::greater);
|
|
||||||
|
|
||||||
always_check((StrongOrder(0, 0) == strong_ordering::equal));
|
|
||||||
always_check((WeakOrder(0, 0) == strong_ordering::equal));
|
|
||||||
always_check((PartialOrder(0, 0) == strong_ordering::equal));
|
|
||||||
always_check((CompareStrongOrderFallback(0, 0) == strong_ordering::equal));
|
|
||||||
always_check((CompareWeakOrderFallback(0, 0) == strong_ordering::equal));
|
|
||||||
always_check((ComparePartialOrderFallback(0, 0) == strong_ordering::equal));
|
|
||||||
|
|
||||||
|
always_check(SynthThreeWayCompare(FTestSynth(-1), FTestSynth( 0)) == weak_ordering::less);
|
||||||
|
always_check(SynthThreeWayCompare(FTestSynth( 0), FTestSynth( 0)) == weak_ordering::equivalent);
|
||||||
|
always_check(SynthThreeWayCompare(FTestSynth( 0), FTestSynth(-1)) == weak_ordering::greater);
|
||||||
}
|
}
|
||||||
|
|
||||||
NAMESPACE_UNNAMED_BEGIN
|
NAMESPACE_UNNAMED_BEGIN
|
||||||
|
@ -68,25 +68,6 @@ struct TCompareThreeWayResult<T, U>
|
|||||||
using Type = decltype(DeclVal<const typename TRemoveReference<T>::Type&>() <=> DeclVal<const typename TRemoveReference<U>::Type&>());
|
using Type = decltype(DeclVal<const typename TRemoveReference<T>::Type&>() <=> DeclVal<const typename TRemoveReference<U>::Type&>());
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T = void> requires (CSameAs<T, void> || CThreeWayComparable<T>)
|
|
||||||
struct TCompareThreeWay
|
|
||||||
{
|
|
||||||
constexpr auto operator()(T&& LHS, T&& RHS) const
|
|
||||||
{
|
|
||||||
return Forward<T>(LHS) <=> Forward<T>(RHS);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct TCompareThreeWay<void>
|
|
||||||
{
|
|
||||||
template <typename T, typename U> requires CThreeWayComparableWith<T, U>
|
|
||||||
constexpr auto operator()(T&& LHS, U&& RHS) const
|
|
||||||
{
|
|
||||||
return Forward<T>(LHS) <=> Forward<U>(RHS);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T, typename OrderingType = partial_ordering>
|
template <typename T, typename OrderingType = partial_ordering>
|
||||||
concept CSynthThreeWayComparable = CThreeWayComparable<T> ||
|
concept CSynthThreeWayComparable = CThreeWayComparable<T> ||
|
||||||
requires(const TRemoveReference<T>::Type& A, const TRemoveReference<T>::Type& B)
|
requires(const TRemoveReference<T>::Type& A, const TRemoveReference<T>::Type& B)
|
||||||
@ -103,27 +84,8 @@ concept CSynthThreeWayComparableWith = CThreeWayComparableWith<T, U> ||
|
|||||||
{ B < A } -> CBooleanTestable;
|
{ B < A } -> CBooleanTestable;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T = void> requires (CSameAs<T, void> || CSynthThreeWayComparable<T>)
|
|
||||||
struct TSynthThreeWay
|
|
||||||
{
|
|
||||||
constexpr auto operator()(T&& LHS, T&& RHS) const
|
|
||||||
{
|
|
||||||
if constexpr (CThreeWayComparable<T>)
|
|
||||||
{
|
|
||||||
return Forward<T>(LHS) <=> Forward<T>(RHS);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Forward<T>(LHS) < Forward<T>(RHS) ? weak_ordering::less : Forward<T>(RHS) < Forward<T>(LHS) ? weak_ordering::greater : weak_ordering::equivalent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct TSynthThreeWay<void>
|
|
||||||
{
|
|
||||||
template <typename T, typename U> requires CSynthThreeWayComparableWith<T, U>
|
template <typename T, typename U> requires CSynthThreeWayComparableWith<T, U>
|
||||||
constexpr auto operator()(T&& LHS, U&& RHS) const
|
constexpr decltype(auto) SynthThreeWayCompare(T&& LHS, U&& RHS)
|
||||||
{
|
{
|
||||||
if constexpr (CThreeWayComparableWith<T, U>)
|
if constexpr (CThreeWayComparableWith<T, U>)
|
||||||
{
|
{
|
||||||
@ -134,25 +96,13 @@ struct TSynthThreeWay<void>
|
|||||||
return Forward<T>(LHS) < Forward<U>(RHS) ? weak_ordering::less : Forward<U>(RHS) < Forward<T>(LHS) ? weak_ordering::greater : weak_ordering::equivalent;
|
return Forward<T>(LHS) < Forward<U>(RHS) ? weak_ordering::less : Forward<U>(RHS) < Forward<T>(LHS) ? weak_ordering::greater : weak_ordering::equivalent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T, typename U = T>
|
template <typename T, typename U = T>
|
||||||
struct TSynthThreeWayResult
|
struct TSynthThreeWayResult
|
||||||
{
|
{
|
||||||
using Type = decltype(TSynthThreeWay{}(DeclVal<const typename TRemoveReference<T>::Type&>(), DeclVal<const typename TRemoveReference<U>::Type&>()));
|
using Type = decltype(SynthThreeWayCompare(DeclVal<const typename TRemoveReference<T>::Type&>(), DeclVal<const typename TRemoveReference<U>::Type&>()));
|
||||||
};
|
};
|
||||||
|
|
||||||
NAMESPACE_UNNAMED_BEGIN
|
|
||||||
|
|
||||||
inline constexpr decltype(NAMESPACE_STD::strong_order) StrongOrder;
|
|
||||||
inline constexpr decltype(NAMESPACE_STD::weak_order) WeakOrder;
|
|
||||||
inline constexpr decltype(NAMESPACE_STD::partial_order) PartialOrder;
|
|
||||||
inline constexpr decltype(NAMESPACE_STD::compare_strong_order_fallback) CompareStrongOrderFallback;
|
|
||||||
inline constexpr decltype(NAMESPACE_STD::compare_weak_order_fallback) CompareWeakOrderFallback;
|
|
||||||
inline constexpr decltype(NAMESPACE_STD::compare_partial_order_fallback) ComparePartialOrderFallback;
|
|
||||||
|
|
||||||
NAMESPACE_UNNAMED_END
|
|
||||||
|
|
||||||
NAMESPACE_MODULE_END(Utility)
|
NAMESPACE_MODULE_END(Utility)
|
||||||
NAMESPACE_MODULE_END(Redcraft)
|
NAMESPACE_MODULE_END(Redcraft)
|
||||||
NAMESPACE_REDCRAFT_END
|
NAMESPACE_REDCRAFT_END
|
||||||
|
@ -501,7 +501,7 @@ struct TTupleThreeWay<R, TIndexSequence<I, Indices...>>
|
|||||||
template <typename LHSTupleType, typename RHSTupleType>
|
template <typename LHSTupleType, typename RHSTupleType>
|
||||||
static constexpr R F(const LHSTupleType& LHS, const RHSTupleType& RHS)
|
static constexpr R F(const LHSTupleType& LHS, const RHSTupleType& RHS)
|
||||||
{
|
{
|
||||||
auto Result = TSynthThreeWay{}(LHS.template GetValue<I>(), RHS.template GetValue<I>());
|
auto Result = SynthThreeWayCompare(LHS.template GetValue<I>(), RHS.template GetValue<I>());
|
||||||
if (Result != 0) return Result;
|
if (Result != 0) return Result;
|
||||||
return TTupleThreeWay<R, TIndexSequence<Indices...>>::F(LHS, RHS);
|
return TTupleThreeWay<R, TIndexSequence<Indices...>>::F(LHS, RHS);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user