File indexing completed on 2026-05-03 08:14:06
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___UTILITY_CMP_H
0010 #define _LIBCPP___UTILITY_CMP_H
0011
0012 #include <__concepts/arithmetic.h>
0013 #include <__config>
0014 #include <__type_traits/is_signed.h>
0015 #include <__type_traits/make_unsigned.h>
0016 #include <limits>
0017
0018 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0019 # pragma GCC system_header
0020 #endif
0021
0022 _LIBCPP_PUSH_MACROS
0023 #include <__undef_macros>
0024
0025 _LIBCPP_BEGIN_NAMESPACE_STD
0026
0027 #if _LIBCPP_STD_VER >= 20
0028
0029 template <__libcpp_integer _Tp, __libcpp_integer _Up>
0030 _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_equal(_Tp __t, _Up __u) noexcept {
0031 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
0032 return __t == __u;
0033 else if constexpr (is_signed_v<_Tp>)
0034 return __t < 0 ? false : make_unsigned_t<_Tp>(__t) == __u;
0035 else
0036 return __u < 0 ? false : __t == make_unsigned_t<_Up>(__u);
0037 }
0038
0039 template <__libcpp_integer _Tp, __libcpp_integer _Up>
0040 _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_not_equal(_Tp __t, _Up __u) noexcept {
0041 return !std::cmp_equal(__t, __u);
0042 }
0043
0044 template <__libcpp_integer _Tp, __libcpp_integer _Up>
0045 _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_less(_Tp __t, _Up __u) noexcept {
0046 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
0047 return __t < __u;
0048 else if constexpr (is_signed_v<_Tp>)
0049 return __t < 0 ? true : make_unsigned_t<_Tp>(__t) < __u;
0050 else
0051 return __u < 0 ? false : __t < make_unsigned_t<_Up>(__u);
0052 }
0053
0054 template <__libcpp_integer _Tp, __libcpp_integer _Up>
0055 _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_greater(_Tp __t, _Up __u) noexcept {
0056 return std::cmp_less(__u, __t);
0057 }
0058
0059 template <__libcpp_integer _Tp, __libcpp_integer _Up>
0060 _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_less_equal(_Tp __t, _Up __u) noexcept {
0061 return !std::cmp_greater(__t, __u);
0062 }
0063
0064 template <__libcpp_integer _Tp, __libcpp_integer _Up>
0065 _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_greater_equal(_Tp __t, _Up __u) noexcept {
0066 return !std::cmp_less(__t, __u);
0067 }
0068
0069 template <__libcpp_integer _Tp, __libcpp_integer _Up>
0070 _LIBCPP_HIDE_FROM_ABI constexpr bool in_range(_Up __u) noexcept {
0071 return std::cmp_less_equal(__u, numeric_limits<_Tp>::max()) &&
0072 std::cmp_greater_equal(__u, numeric_limits<_Tp>::min());
0073 }
0074
0075 #endif
0076
0077 _LIBCPP_END_NAMESPACE_STD
0078
0079 _LIBCPP_POP_MACROS
0080
0081 #endif