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

Message ID 20230321163949.1950-2-kmatsui@cs.washington.edu
State Accepted
Headers
Series [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 March 21, 2023, 4:39 p.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.
---
 libstdc++-v3/include/std/type_traits | 7 +++++++
 1 file changed, 7 insertions(+)
  

Comments

Jonathan Wakely March 21, 2023, 4:44 p.m. UTC | #1
On Tue, 21 Mar 2023 at 16:41, 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.
>

Please wrap the ChangeLog entry to less than 80 columns (including 8 for
the leading tab).



> ---
>  libstdc++-v3/include/std/type_traits | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/libstdc++-v3/include/std/type_traits
> b/libstdc++-v3/include/std/type_traits
> index 2bd607a8b8f..8d5a05cd0a6 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
>

Thanks, I expect this trait to make a much bigger difference than
add_const, so I'm very happy to see this one!



>
>    /// @cond undocumented
>    template<typename _Tp, typename _Up = _Tp&&>
> --
> 2.40.0
>
>
  
Ken Matsui March 21, 2023, 5:02 p.m. UTC | #2
I see. Thank you!


On Tue, Mar 21, 2023 at 9:44 AM Jonathan Wakely <jwakely@redhat.com> wrote:

>
>
> On Tue, 21 Mar 2023 at 16:41, 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.
>>
>
> Please wrap the ChangeLog entry to less than 80 columns (including 8 for
> the leading tab).
>
>
>
>> ---
>>  libstdc++-v3/include/std/type_traits | 7 +++++++
>>  1 file changed, 7 insertions(+)
>>
>> diff --git a/libstdc++-v3/include/std/type_traits
>> b/libstdc++-v3/include/std/type_traits
>> index 2bd607a8b8f..8d5a05cd0a6 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
>>
>
> Thanks, I expect this trait to make a much bigger difference than
> add_const, so I'm very happy to see this one!
>
>
>
>>
>>    /// @cond undocumented
>>    template<typename _Tp, typename _Up = _Tp&&>
>> --
>> 2.40.0
>>
>>
  

Patch

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 2bd607a8b8f..8d5a05cd0a6 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&&>