From e0a6905287050d57ea0413cba7f011803b1f65ef Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Fri, 18 Apr 2025 09:06:21 +0200 Subject: [PATCH] [libc++] Simplify the generic implementation of is_{un}signed (#136095) --- libcxx/include/__type_traits/is_signed.h | 15 ++++----------- libcxx/include/__type_traits/is_unsigned.h | 15 ++++----------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/libcxx/include/__type_traits/is_signed.h b/libcxx/include/__type_traits/is_signed.h index 4aae921f293c..02f51f9cc9b1 100644 --- a/libcxx/include/__type_traits/is_signed.h +++ b/libcxx/include/__type_traits/is_signed.h @@ -12,7 +12,6 @@ #include <__config> #include <__type_traits/integral_constant.h> #include <__type_traits/is_arithmetic.h> -#include <__type_traits/is_integral.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -32,24 +31,18 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_signed_v = __is_signed(_Tp); #else // __has_builtin(__is_signed) -template ::value> -struct __libcpp_is_signed_impl : _BoolConstant<(_Tp(-1) < _Tp(0))> {}; - -template -struct __libcpp_is_signed_impl<_Tp, false> : true_type {}; // floating point - template ::value> -struct __libcpp_is_signed : __libcpp_is_signed_impl<_Tp> {}; +inline constexpr bool __is_signed_v = false; template -struct __libcpp_is_signed<_Tp, false> : false_type {}; +inline constexpr bool __is_signed_v<_Tp, true> = _Tp(-1) < _Tp(0); template -struct is_signed : __libcpp_is_signed<_Tp> {}; +struct is_signed : integral_constant> {}; # if _LIBCPP_STD_VER >= 17 template -inline constexpr bool is_signed_v = is_signed<_Tp>::value; +inline constexpr bool is_signed_v = __is_signed_v<_Tp>; # endif #endif // __has_builtin(__is_signed) diff --git a/libcxx/include/__type_traits/is_unsigned.h b/libcxx/include/__type_traits/is_unsigned.h index 900ff969eae0..b66027c8d779 100644 --- a/libcxx/include/__type_traits/is_unsigned.h +++ b/libcxx/include/__type_traits/is_unsigned.h @@ -11,7 +11,6 @@ #include <__config> #include <__type_traits/integral_constant.h> -#include <__type_traits/is_arithmetic.h> #include <__type_traits/is_integral.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -33,23 +32,17 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_unsigned_v = __is_unsigned(_ #else // __has_builtin(__is_unsigned) template ::value> -struct __libcpp_is_unsigned_impl : public _BoolConstant<(_Tp(0) < _Tp(-1))> {}; +inline constexpr bool __is_unsigned_v = false; template -struct __libcpp_is_unsigned_impl<_Tp, false> : public false_type {}; // floating point - -template ::value> -struct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {}; +inline constexpr bool __is_unsigned_v<_Tp, true> = _Tp(0) < _Tp(-1); template -struct __libcpp_is_unsigned<_Tp, false> : public false_type {}; - -template -struct is_unsigned : public __libcpp_is_unsigned<_Tp> {}; +struct is_unsigned : integral_constant> {}; # if _LIBCPP_STD_VER >= 17 template -inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value; +inline constexpr bool is_unsigned_v = __is_unsigned_v<_Tp>; # endif #endif // __has_builtin(__is_unsigned)