@@ -26,16 +26,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
26
26
27
27
#if _LIBCPP_STD_VER >= 20
28
28
29
+ template <__signed_or_unsigned_integer _Tp, __signed_integer _Ip>
30
+ inline constexpr bool __comparison_can_promote_to =
31
+ __signed_integer<_Tp> ? sizeof (_Tp) <= sizeof (_Ip) : sizeof (_Tp) < sizeof (_Ip);
32
+
29
33
template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up>
30
34
_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_equal (_Tp __t , _Up __u) noexcept {
31
- if constexpr (sizeof (_Tp) < sizeof (int ) && sizeof (_Up) < sizeof (int )) {
32
- __builtin_assume (__t < numeric_limits<int >::max () && __u < numeric_limits<int >::max ());
35
+ if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
36
+ return __t == __u;
37
+ else if constexpr (__comparison_can_promote_to<_Tp, int > && __comparison_can_promote_to<_Up, int >)
33
38
return static_cast <int >(__t ) == static_cast <int >(__u);
34
- } else if constexpr (sizeof (_Tp) < sizeof (long long ) && sizeof (_Up) < sizeof (long long )) {
35
- __builtin_assume (__t < numeric_limits<long long >::max () && __u < numeric_limits<long long >::max ());
39
+ else if constexpr (__comparison_can_promote_to<_Tp, long long > && __comparison_can_promote_to<_Up, long long >)
36
40
return static_cast <long long >(__t ) == static_cast <long long >(__u);
37
- } else if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
38
- return __t == __u;
39
41
else if constexpr (is_signed_v<_Tp>)
40
42
return __t < 0 ? false : make_unsigned_t <_Tp>(__t ) == __u;
41
43
else
@@ -49,14 +51,12 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_not_equal(_Tp __t, _Up __u) noexcept {
49
51
50
52
template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up>
51
53
_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_less (_Tp __t , _Up __u) noexcept {
52
- if constexpr (sizeof (_Tp) < sizeof (int ) && sizeof (_Up) < sizeof (int )) {
53
- __builtin_assume (__t < numeric_limits<int >::max () && __u < numeric_limits<int >::max ());
54
+ if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
55
+ return __t < __u;
56
+ else if constexpr (__comparison_can_promote_to<_Tp, int > && __comparison_can_promote_to<_Up, int >)
54
57
return static_cast <int >(__t ) < static_cast <int >(__u);
55
- } else if constexpr (sizeof (_Tp) < sizeof (long long ) && sizeof (_Up) < sizeof (long long )) {
56
- __builtin_assume (__t < numeric_limits<long long >::max () && __u < numeric_limits<long long >::max ());
58
+ else if constexpr (__comparison_can_promote_to<_Tp, long long > && __comparison_can_promote_to<_Up, long long >)
57
59
return static_cast <long long >(__t ) < static_cast <long long >(__u);
58
- } else if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
59
- return __t < __u;
60
60
else if constexpr (is_signed_v<_Tp>)
61
61
return __t < 0 ? true : make_unsigned_t <_Tp>(__t ) < __u;
62
62
else
0 commit comments