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

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

Checks

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

Commit Message

Ken Matsui July 10, 2023, 5:23 a.m. UTC
  This patch lets libstdc++ use new built-in trait __is_pointer.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_pointer): Use __is_pointer
	built-in trait.
	(is_pointer_v): Likewise.

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

Comments

Daniel Krügler July 10, 2023, 5:32 a.m. UTC | #1
Am Mo., 10. Juli 2023 um 07:24 Uhr schrieb Ken Matsui via Libstdc++
<libstdc++@gcc.gnu.org>:
>
> This patch lets libstdc++ use new built-in trait __is_pointer.
>
> libstdc++-v3/ChangeLog:
>
>         * include/std/type_traits (is_pointer): Use __is_pointer
>         built-in trait.
>         (is_pointer_v): Likewise.
>
> Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
> ---
>  libstdc++-v3/include/std/type_traits | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> index 0e7a9c9c7f3..d83db98403b 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -515,6 +515,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      struct is_array<_Tp[]>
>      : public true_type { };
>
> +  /// is_pointer
> +#if __has_builtin(__is_pointer)
> +  template<typename _Tp>
> +    struct is_pointer
> +    : public __bool_constant<__is_pointer(_Tp)>
> +    { };
> +#else
>    template<typename>
>      struct __is_pointer_helper
>      : public false_type { };
> @@ -523,11 +530,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      struct __is_pointer_helper<_Tp*>
>      : public true_type { };
>
> -  /// is_pointer
>    template<typename _Tp>
>      struct is_pointer
>      : public __is_pointer_helper<__remove_cv_t<_Tp>>::type
>      { };
> +#endif
>
>    /// is_lvalue_reference
>    template<typename>
> --
> 2.41.0

Shouldn't this adjust is_pointer_v as well?

Thanks,

- Daniel
  
Ken Matsui July 10, 2023, 5:34 a.m. UTC | #2
Oops! Thank you for pointing that out!

Sincerely,
Ken Matsui

On Sun, Jul 9, 2023 at 10:33 PM Daniel Krügler
<daniel.kruegler@gmail.com> wrote:
>
> Am Mo., 10. Juli 2023 um 07:24 Uhr schrieb Ken Matsui via Libstdc++
> <libstdc++@gcc.gnu.org>:
> >
> > This patch lets libstdc++ use new built-in trait __is_pointer.
> >
> > libstdc++-v3/ChangeLog:
> >
> >         * include/std/type_traits (is_pointer): Use __is_pointer
> >         built-in trait.
> >         (is_pointer_v): Likewise.
> >
> > Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
> > ---
> >  libstdc++-v3/include/std/type_traits | 9 ++++++++-
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> > index 0e7a9c9c7f3..d83db98403b 100644
> > --- a/libstdc++-v3/include/std/type_traits
> > +++ b/libstdc++-v3/include/std/type_traits
> > @@ -515,6 +515,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >      struct is_array<_Tp[]>
> >      : public true_type { };
> >
> > +  /// is_pointer
> > +#if __has_builtin(__is_pointer)
> > +  template<typename _Tp>
> > +    struct is_pointer
> > +    : public __bool_constant<__is_pointer(_Tp)>
> > +    { };
> > +#else
> >    template<typename>
> >      struct __is_pointer_helper
> >      : public false_type { };
> > @@ -523,11 +530,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >      struct __is_pointer_helper<_Tp*>
> >      : public true_type { };
> >
> > -  /// is_pointer
> >    template<typename _Tp>
> >      struct is_pointer
> >      : public __is_pointer_helper<__remove_cv_t<_Tp>>::type
> >      { };
> > +#endif
> >
> >    /// is_lvalue_reference
> >    template<typename>
> > --
> > 2.41.0
>
> Shouldn't this adjust is_pointer_v as well?
>
> Thanks,
>
> - Daniel
  

Patch

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 0e7a9c9c7f3..d83db98403b 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -515,6 +515,13 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct is_array<_Tp[]>
     : public true_type { };
 
+  /// is_pointer
+#if __has_builtin(__is_pointer)
+  template<typename _Tp>
+    struct is_pointer
+    : public __bool_constant<__is_pointer(_Tp)>
+    { };
+#else
   template<typename>
     struct __is_pointer_helper
     : public false_type { };
@@ -523,11 +530,11 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct __is_pointer_helper<_Tp*>
     : public true_type { };
 
-  /// is_pointer
   template<typename _Tp>
     struct is_pointer
     : public __is_pointer_helper<__remove_cv_t<_Tp>>::type
     { };
+#endif
 
   /// is_lvalue_reference
   template<typename>