@@ -27,9 +27,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
27
27
template <class _LHS , class _RHS , class = void >
28
28
struct __default_three_way_comparator ;
29
29
30
- template <class _Tp >
31
- struct __default_three_way_comparator <_Tp, _Tp, __enable_if_t <is_arithmetic<_Tp>::value> > {
32
- _LIBCPP_HIDE_FROM_ABI static int operator ()(_Tp __lhs, _Tp __rhs) {
30
+ template <class _LHS , class _RHS >
31
+ struct __default_three_way_comparator <_LHS,
32
+ _RHS,
33
+ __enable_if_t <is_arithmetic<_LHS>::value && is_arithmetic<_RHS>::value> > {
34
+ _LIBCPP_HIDE_FROM_ABI static int operator ()(_LHS __lhs, _RHS __rhs) {
33
35
if (__lhs < __rhs)
34
36
return -1 ;
35
37
if (__lhs > __rhs)
@@ -38,6 +40,24 @@ struct __default_three_way_comparator<_Tp, _Tp, __enable_if_t<is_arithmetic<_Tp>
38
40
}
39
41
};
40
42
43
+ #if _LIBCPP_STD_VER >= 20 && __has_builtin(__builtin_lt_synthesises_from_spaceship)
44
+ template <class _LHS , class _RHS >
45
+ struct __default_three_way_comparator <
46
+ _LHS,
47
+ _RHS,
48
+ __enable_if_t <(!is_arithmetic<_LHS>::value || !is_arithmetic<_RHS>::value) &&
49
+ __builtin_lt_synthesises_from_spaceship (const _LHS&, const _RHS&)>> {
50
+ _LIBCPP_HIDE_FROM_ABI static int operator ()(const _LHS& __lhs, const _RHS& __rhs) {
51
+ auto __res = __lhs <=> __rhs;
52
+ if (__res < 0 )
53
+ return -1 ;
54
+ if (__res > 0 )
55
+ return 1 ;
56
+ return 0 ;
57
+ }
58
+ };
59
+ #endif
60
+
41
61
template <class _LHS , class _RHS , bool = true >
42
62
inline const bool __has_default_three_way_comparator_v = false ;
43
63
0 commit comments