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

Message ID 20230322001142.13422-2-kmatsui@cs.washington.edu
State Accepted
Headers
Series [1/2] c++: implement __is_const built-in trait |

Checks

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

Commit Message

Ken Matsui March 22, 2023, 12:11 a.m. UTC
  This patch lets libstdc++ use new built-in trait __is_const.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_const): Use __is_const built-in trait.
---
 libstdc++-v3/include/std/type_traits | 7 +++++++
 1 file changed, 7 insertions(+)
  

Comments

Patrick Palka June 20, 2023, 4:11 p.m. UTC | #1
On Tue, 21 Mar 2023, Ken Matsui wrote:

> This patch lets libstdc++ use new built-in trait __is_const.
> 
> libstdc++-v3/ChangeLog:
> 
> 	* include/std/type_traits (is_const): Use __is_const built-in trait.

We should also use it in is_const_v (likewise for the __is_array and
__is_volatile patches).

> ---
>  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..e77de828501 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -764,6 +764,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>    // Type properties.
>  
>    /// is_const
> +#if __has_builtin(__is_const)
> +  template<typename _Tp>
> +    struct is_const
> +    : public __bool_constant<__is_const(_Tp)>
> +    { };
> +#else
>    template<typename>
>      struct is_const
>      : public false_type { };
> @@ -771,6 +777,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>    template<typename _Tp>
>      struct is_const<_Tp const>
>      : public true_type { };
> +#endif
>  
>    /// is_volatile
>    template<typename>
> -- 
> 2.40.0
> 
>
  

Patch

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 2bd607a8b8f..e77de828501 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -764,6 +764,12 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Type properties.
 
   /// is_const
+#if __has_builtin(__is_const)
+  template<typename _Tp>
+    struct is_const
+    : public __bool_constant<__is_const(_Tp)>
+    { };
+#else
   template<typename>
     struct is_const
     : public false_type { };
@@ -771,6 +777,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Tp>
     struct is_const<_Tp const>
     : public true_type { };
+#endif
 
   /// is_volatile
   template<typename>