[v4,2/2] libstdc++: use new built-in trait __is_unsigned

Message ID 20230708111308.92402-2-kmatsui@gcc.gnu.org
State Accepted
Headers
Series [v4,1/2] c++: implement __is_unsigned built-in trait |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Ken Matsui July 8, 2023, 11:13 a.m. UTC
  This patch lets libstdc++ use new built-in trait __is_unsigned.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_unsigned): Use __is_unsigned built-in
	trait.
	(is_unsigned_v): Likewise.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
---
 libstdc++-v3/include/std/type_traits | 13 +++++++++++++
 1 file changed, 13 insertions(+)
  

Comments

Jonathan Wakely July 12, 2023, 10:04 a.m. UTC | #1
On Sat, 8 Jul 2023 at 12:14, Ken Matsui via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> This patch lets libstdc++ use new built-in trait __is_unsigned.
>
> libstdc++-v3/ChangeLog:
>
>         * include/std/type_traits (is_unsigned): Use __is_unsigned built-in
>         trait.
>         (is_unsigned_v): Likewise.
>
> Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>

OK for trunk after the front-end implementation of __is_unsigned is committed.


> ---
>  libstdc++-v3/include/std/type_traits | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> index 0e7a9c9c7f3..7eeb0da7a27 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -884,10 +884,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      { };
>
>    /// is_unsigned
> +#if __has_builtin(__is_unsigned)
> +  template<typename _Tp>
> +    struct is_unsigned
> +    : public __bool_constant<__is_unsigned(_Tp)>
> +    { };
> +#else
>    template<typename _Tp>
>      struct is_unsigned
>      : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
>      { };
> +#endif
>
>    /// @cond undocumented
>    template<typename _Tp, typename _Up = _Tp&&>
> @@ -3242,8 +3249,14 @@ template <typename _Tp>
>
>  template <typename _Tp>
>    inline constexpr bool is_signed_v = is_signed<_Tp>::value;
> +
> +#if __has_builtin(__is_unsigned)
> +template <typename _Tp>
> +  inline constexpr bool is_unsigned_v = __is_unsigned(_Tp);
> +#else
>  template <typename _Tp>
>    inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
> +#endif
>
>  template <typename _Tp, typename... _Args>
>    inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);
> --
> 2.41.0
>
  

Patch

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 0e7a9c9c7f3..7eeb0da7a27 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -884,10 +884,17 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     { };
 
   /// is_unsigned
+#if __has_builtin(__is_unsigned)
+  template<typename _Tp>
+    struct is_unsigned
+    : public __bool_constant<__is_unsigned(_Tp)>
+    { };
+#else
   template<typename _Tp>
     struct is_unsigned
     : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
     { };
+#endif
 
   /// @cond undocumented
   template<typename _Tp, typename _Up = _Tp&&>
@@ -3242,8 +3249,14 @@  template <typename _Tp>
 
 template <typename _Tp>
   inline constexpr bool is_signed_v = is_signed<_Tp>::value;
+
+#if __has_builtin(__is_unsigned)
+template <typename _Tp>
+  inline constexpr bool is_unsigned_v = __is_unsigned(_Tp);
+#else
 template <typename _Tp>
   inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
+#endif
 
 template <typename _Tp, typename... _Args>
   inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);