Skip to content

Commit 1705894

Browse files
H-G-HristovZingam
andauthored
[libc++][utility][NFC] Refactored safe integer cmp_xxxx functions to use the __libcpp_is_integer concept (llvm#78115)
Replaced a functionally identical internal concept helper. References: - https://eel.is/c++draft/utility.intcmp - https://eel.is/c++draft/basic.fundamental Co-authored-by: Zingam <[email protected]>
1 parent 26d3cd1 commit 1705894

File tree

1 file changed

+10
-33
lines changed
  • libcxx/include/__utility

1 file changed

+10
-33
lines changed

libcxx/include/__utility/cmp.h

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@
99
#ifndef _LIBCPP___UTILITY_CMP_H
1010
#define _LIBCPP___UTILITY_CMP_H
1111

12+
#include <__concepts/arithmetic.h>
1213
#include <__config>
13-
#include <__type_traits/disjunction.h>
14-
#include <__type_traits/is_integral.h>
15-
#include <__type_traits/is_same.h>
1614
#include <__type_traits/is_signed.h>
1715
#include <__type_traits/make_unsigned.h>
18-
#include <__utility/forward.h>
19-
#include <__utility/move.h>
2016
#include <limits>
2117

2218
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -29,28 +25,8 @@ _LIBCPP_PUSH_MACROS
2925
_LIBCPP_BEGIN_NAMESPACE_STD
3026

3127
#if _LIBCPP_STD_VER >= 20
32-
template <class _Tp, class... _Up>
33-
struct _IsSameAsAny : _Or<_IsSame<_Tp, _Up>...> {};
34-
35-
template <class _Tp>
36-
concept __is_safe_integral_cmp =
37-
is_integral_v<_Tp> &&
38-
!_IsSameAsAny<_Tp,
39-
bool,
40-
char,
41-
char16_t,
42-
char32_t
43-
# ifndef _LIBCPP_HAS_NO_CHAR8_T
44-
,
45-
char8_t
46-
# endif
47-
# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
48-
,
49-
wchar_t
50-
# endif
51-
>::value;
52-
53-
template <__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up>
28+
29+
template <__libcpp_integer _Tp, __libcpp_integer _Up>
5430
_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_equal(_Tp __t, _Up __u) noexcept {
5531
if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
5632
return __t == __u;
@@ -60,12 +36,12 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_equal(_Tp __t, _Up __u) noexcept {
6036
return __u < 0 ? false : __t == make_unsigned_t<_Up>(__u);
6137
}
6238

63-
template <__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up>
39+
template <__libcpp_integer _Tp, __libcpp_integer _Up>
6440
_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_not_equal(_Tp __t, _Up __u) noexcept {
6541
return !std::cmp_equal(__t, __u);
6642
}
6743

68-
template <__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up>
44+
template <__libcpp_integer _Tp, __libcpp_integer _Up>
6945
_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_less(_Tp __t, _Up __u) noexcept {
7046
if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
7147
return __t < __u;
@@ -75,26 +51,27 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_less(_Tp __t, _Up __u) noexcept {
7551
return __u < 0 ? false : __t < make_unsigned_t<_Up>(__u);
7652
}
7753

78-
template <__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up>
54+
template <__libcpp_integer _Tp, __libcpp_integer _Up>
7955
_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_greater(_Tp __t, _Up __u) noexcept {
8056
return std::cmp_less(__u, __t);
8157
}
8258

83-
template <__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up>
59+
template <__libcpp_integer _Tp, __libcpp_integer _Up>
8460
_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_less_equal(_Tp __t, _Up __u) noexcept {
8561
return !std::cmp_greater(__t, __u);
8662
}
8763

88-
template <__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up>
64+
template <__libcpp_integer _Tp, __libcpp_integer _Up>
8965
_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_greater_equal(_Tp __t, _Up __u) noexcept {
9066
return !std::cmp_less(__t, __u);
9167
}
9268

93-
template <__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up>
69+
template <__libcpp_integer _Tp, __libcpp_integer _Up>
9470
_LIBCPP_HIDE_FROM_ABI constexpr bool in_range(_Up __u) noexcept {
9571
return std::cmp_less_equal(__u, numeric_limits<_Tp>::max()) &&
9672
std::cmp_greater_equal(__u, numeric_limits<_Tp>::min());
9773
}
74+
9875
#endif // _LIBCPP_STD_VER >= 20
9976

10077
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)