forked from Alepha/Alepha
Remove more enable_if_t for comparisions.
This commit is contained in:
@ -30,6 +30,8 @@ namespace Alepha::Hydrogen
|
||||
using detail::comparisons_m::comparable;
|
||||
}
|
||||
|
||||
// TODO: This name collides with `Concepts::Comparable` in annoying ways, it seems.
|
||||
// Maybe rename to `LensComparable`?
|
||||
template< typename T >
|
||||
concept Comparable= HasCapability< T, comparable >;
|
||||
|
||||
@ -130,23 +132,17 @@ namespace Alepha::Hydrogen
|
||||
|
||||
// Equality Lens support
|
||||
|
||||
template< typename T, typename= void >
|
||||
struct has_equality_lens_member : std::false_type {};
|
||||
|
||||
template< typename T >
|
||||
struct has_equality_lens_member< T, std::void_t< decltype( std::declval< const T & >().equality_lens() ) > > : std::true_type {};
|
||||
concept MemberEqualityLensed=
|
||||
Comparable< T >
|
||||
and
|
||||
requires( const T &val )
|
||||
{
|
||||
{ val.equality_lens() } -> Concepts::EqualityComparable;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
constexpr bool has_equality_lens_member_v= has_equality_lens_member< T >::value;
|
||||
|
||||
template
|
||||
<
|
||||
Comparable T,
|
||||
typename= std::enable_if_t< has_equality_lens_member_v< T > >,
|
||||
overload< __LINE__ > = nullptr
|
||||
>
|
||||
constexpr decltype( auto )
|
||||
equality_lens( T &t )
|
||||
equality_lens( MemberEqualityLensed auto &t )
|
||||
{
|
||||
return t.equality_lens();
|
||||
}
|
||||
@ -163,20 +159,20 @@ namespace Alepha::Hydrogen
|
||||
return value_lens( t );
|
||||
}
|
||||
|
||||
template< typename T, typename= void >
|
||||
struct supports_equality_lens : std::false_type {};
|
||||
|
||||
template< typename T >
|
||||
struct supports_equality_lens< T, std::void_t< decltype( equality_lens( std::declval< const T & >() ) ) > > : std::true_type {};
|
||||
|
||||
template< typename T >
|
||||
constexpr bool supports_equality_lens_v= supports_equality_lens< T >::value;
|
||||
concept EqualityLensed=
|
||||
Comparable< T >
|
||||
and
|
||||
requires( const T &val )
|
||||
{
|
||||
{ equality_lens( val ) } -> Concepts::EqualityComparable;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
constexpr decltype( auto )
|
||||
make_equality_lens( T &t )
|
||||
{
|
||||
if constexpr( supports_equality_lens_v< T > ) return equality_lens( t );
|
||||
if constexpr( EqualityLensed< T > ) return equality_lens( t );
|
||||
//else if constexpr( supports_default_lens_v< T > ) return default_lens( t );
|
||||
else static_assert( Meta::dep_value< false, T > );
|
||||
}
|
||||
@ -235,66 +231,42 @@ namespace Alepha::Hydrogen
|
||||
}
|
||||
|
||||
// Operator support:
|
||||
template
|
||||
<
|
||||
Comparable T,
|
||||
overload< __LINE__ > = nullptr
|
||||
>
|
||||
template< Comparable T >
|
||||
constexpr bool
|
||||
operator == ( const T &lhs, const T &rhs )
|
||||
{
|
||||
return make_equality_lens( lhs ) == make_equality_lens( rhs );
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
Comparable T,
|
||||
overload< __LINE__ > = nullptr
|
||||
>
|
||||
template< Comparable T >
|
||||
constexpr bool
|
||||
operator != ( const T &lhs, const T &rhs )
|
||||
{
|
||||
return make_equality_lens( lhs ) != make_equality_lens( rhs );
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
Comparable T,
|
||||
overload< __LINE__ > = nullptr
|
||||
>
|
||||
template< Comparable T >
|
||||
constexpr bool
|
||||
operator < ( const T &lhs, const T &rhs )
|
||||
{
|
||||
return make_strict_weak_order_lens( lhs ) < make_strict_weak_order_lens( rhs );
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
Comparable T,
|
||||
overload< __LINE__ > = nullptr
|
||||
>
|
||||
template< Comparable T >
|
||||
constexpr bool
|
||||
operator > ( const T &lhs, const T &rhs )
|
||||
{
|
||||
return make_strict_weak_order_lens( lhs ) > make_strict_weak_order_lens( rhs );
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
Comparable T,
|
||||
overload< __LINE__ > = nullptr
|
||||
>
|
||||
template< Comparable T >
|
||||
constexpr bool
|
||||
operator <= ( const T &lhs, const T &rhs )
|
||||
{
|
||||
return make_strict_weak_order_lens( lhs ) <= make_strict_weak_order_lens( rhs );
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
Comparable T,
|
||||
overload< __LINE__ > = nullptr
|
||||
>
|
||||
template< Comparable T >
|
||||
constexpr bool
|
||||
operator >= ( const T &lhs, const T &rhs )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user