-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Simplify the generic implementation of is_{un}signed #136095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-libcxx Author: Nikolas Klauser (philnik777) ChangesFull diff: https://github.com/llvm/llvm-project/pull/136095.diff 2 Files Affected:
diff --git a/libcxx/include/__type_traits/is_signed.h b/libcxx/include/__type_traits/is_signed.h
index 4aae921f293c9..02f51f9cc9b19 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 <class _Tp, bool = is_integral<_Tp>::value>
-struct __libcpp_is_signed_impl : _BoolConstant<(_Tp(-1) < _Tp(0))> {};
-
-template <class _Tp>
-struct __libcpp_is_signed_impl<_Tp, false> : true_type {}; // floating point
-
template <class _Tp, bool = is_arithmetic<_Tp>::value>
-struct __libcpp_is_signed : __libcpp_is_signed_impl<_Tp> {};
+inline constexpr bool __is_signed_v = false;
template <class _Tp>
-struct __libcpp_is_signed<_Tp, false> : false_type {};
+inline constexpr bool __is_signed_v<_Tp, true> = _Tp(-1) < _Tp(0);
template <class _Tp>
-struct is_signed : __libcpp_is_signed<_Tp> {};
+struct is_signed : integral_constant<bool, __is_signed_v<_Tp>> {};
# if _LIBCPP_STD_VER >= 17
template <class _Tp>
-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 900ff969eae0e..b66027c8d7791 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 <class _Tp, bool = is_integral<_Tp>::value>
-struct __libcpp_is_unsigned_impl : public _BoolConstant<(_Tp(0) < _Tp(-1))> {};
+inline constexpr bool __is_unsigned_v = false;
template <class _Tp>
-struct __libcpp_is_unsigned_impl<_Tp, false> : public false_type {}; // floating point
-
-template <class _Tp, bool = is_arithmetic<_Tp>::value>
-struct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {};
-
-template <class _Tp>
-struct __libcpp_is_unsigned<_Tp, false> : public false_type {};
+inline constexpr bool __is_unsigned_v<_Tp, true> = _Tp(0) < _Tp(-1);
template <class _Tp>
-struct is_unsigned : public __libcpp_is_unsigned<_Tp> {};
+struct is_unsigned : integral_constant<bool, __is_unsigned_v<_Tp>> {};
# if _LIBCPP_STD_VER >= 17
template <class _Tp>
-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)
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/3714 Here is the relevant piece of the build log for the reference
|
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.