Skip to content

Commit e0a6905

Browse files
authored
[libc++] Simplify the generic implementation of is_{un}signed (#136095)
1 parent cc7fc99 commit e0a6905

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

libcxx/include/__type_traits/is_signed.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <__config>
1313
#include <__type_traits/integral_constant.h>
1414
#include <__type_traits/is_arithmetic.h>
15-
#include <__type_traits/is_integral.h>
1615

1716
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1817
# pragma GCC system_header
@@ -32,24 +31,18 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_signed_v = __is_signed(_Tp);
3231

3332
#else // __has_builtin(__is_signed)
3433

35-
template <class _Tp, bool = is_integral<_Tp>::value>
36-
struct __libcpp_is_signed_impl : _BoolConstant<(_Tp(-1) < _Tp(0))> {};
37-
38-
template <class _Tp>
39-
struct __libcpp_is_signed_impl<_Tp, false> : true_type {}; // floating point
40-
4134
template <class _Tp, bool = is_arithmetic<_Tp>::value>
42-
struct __libcpp_is_signed : __libcpp_is_signed_impl<_Tp> {};
35+
inline constexpr bool __is_signed_v = false;
4336

4437
template <class _Tp>
45-
struct __libcpp_is_signed<_Tp, false> : false_type {};
38+
inline constexpr bool __is_signed_v<_Tp, true> = _Tp(-1) < _Tp(0);
4639

4740
template <class _Tp>
48-
struct is_signed : __libcpp_is_signed<_Tp> {};
41+
struct is_signed : integral_constant<bool, __is_signed_v<_Tp>> {};
4942

5043
# if _LIBCPP_STD_VER >= 17
5144
template <class _Tp>
52-
inline constexpr bool is_signed_v = is_signed<_Tp>::value;
45+
inline constexpr bool is_signed_v = __is_signed_v<_Tp>;
5346
# endif
5447

5548
#endif // __has_builtin(__is_signed)

libcxx/include/__type_traits/is_unsigned.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <__config>
1313
#include <__type_traits/integral_constant.h>
14-
#include <__type_traits/is_arithmetic.h>
1514
#include <__type_traits/is_integral.h>
1615

1716
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -33,23 +32,17 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_unsigned_v = __is_unsigned(_
3332
#else // __has_builtin(__is_unsigned)
3433

3534
template <class _Tp, bool = is_integral<_Tp>::value>
36-
struct __libcpp_is_unsigned_impl : public _BoolConstant<(_Tp(0) < _Tp(-1))> {};
35+
inline constexpr bool __is_unsigned_v = false;
3736

3837
template <class _Tp>
39-
struct __libcpp_is_unsigned_impl<_Tp, false> : public false_type {}; // floating point
40-
41-
template <class _Tp, bool = is_arithmetic<_Tp>::value>
42-
struct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {};
43-
44-
template <class _Tp>
45-
struct __libcpp_is_unsigned<_Tp, false> : public false_type {};
38+
inline constexpr bool __is_unsigned_v<_Tp, true> = _Tp(0) < _Tp(-1);
4639

4740
template <class _Tp>
48-
struct is_unsigned : public __libcpp_is_unsigned<_Tp> {};
41+
struct is_unsigned : integral_constant<bool, __is_unsigned_v<_Tp>> {};
4942

5043
# if _LIBCPP_STD_VER >= 17
5144
template <class _Tp>
52-
inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
45+
inline constexpr bool is_unsigned_v = __is_unsigned_v<_Tp>;
5346
# endif
5447

5548
#endif // __has_builtin(__is_unsigned)

0 commit comments

Comments
 (0)