diff mbox series

libstdc++: Use __is_invocable/nothrow_invocable builtins more

Message ID 20250129185449.1756675-1-ppalka@redhat.com
State New
Headers show
Series libstdc++: Use __is_invocable/nothrow_invocable builtins more | expand

Commit Message

Patrick Palka Jan. 29, 2025, 6:54 p.m. UTC
Tested on x86_64-pc-linux-gnu, I suppose this is stage 1 material?

-- >8 --

As a follow-up to r15-1253 and r15-1254.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (__is_invocable): Define in terms of
	corresponding builtin if available.
	(__is_nothrow_invocable): Likewise.
	(is_invocable_v): Likewise.
	(is_nothrow_invocable_v): Likewise.
---
 libstdc++-v3/include/std/type_traits | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Comments

Jonathan Wakely March 6, 2025, 4:29 p.m. UTC | #1
On Wed, 29 Jan 2025 at 18:55, Patrick Palka wrote:
>
> Tested on x86_64-pc-linux-gnu, I suppose this is stage 1 material?

Yes, I think so, since it could impact C++17 programs.

OK for trunk as soon as stage 1 opens though, thanks.


>
> -- >8 --
>
> As a follow-up to r15-1253 and r15-1254.
>
> libstdc++-v3/ChangeLog:
>
>         * include/std/type_traits (__is_invocable): Define in terms of
>         corresponding builtin if available.
>         (__is_nothrow_invocable): Likewise.
>         (is_invocable_v): Likewise.
>         (is_nothrow_invocable_v): Likewise.
> ---
>  libstdc++-v3/include/std/type_traits | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> index 33892818257..f576d5b1426 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -3211,7 +3211,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>
>    template<typename _Fn, typename... _ArgTypes>
>      struct __is_invocable
> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
> +    : __bool_constant<__is_invocable(_Fn, _ArgTypes...)>
> +#else
>      : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
> +#endif
>      { };
>
>    template<typename _Fn, typename _Tp, typename... _Args>
> @@ -3262,8 +3266,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>    // __is_nothrow_invocable (std::is_nothrow_invocable for C++11)
>    template<typename _Fn, typename... _Args>
>      struct __is_nothrow_invocable
> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
> +    : __bool_constant<__is_nothrow_invocable(_Fn, _Args...)>
> +#else
>      : __and_<__is_invocable<_Fn, _Args...>,
>               __call_is_nothrow_<_Fn, _Args...>>::type
> +#endif
>      { };
>
>  #pragma GCC diagnostic push
> @@ -3702,10 +3710,19 @@ template <typename _From, typename _To>
>    inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
>  #endif
>  template<typename _Fn, typename... _Args>
> -  inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
> +  inline constexpr bool is_invocable_v
> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
> +    = __is_invocable(_Fn, _Args...);
> +#else
> +    = is_invocable<_Fn, _Args...>::value;
> +#endif
>  template<typename _Fn, typename... _Args>
>    inline constexpr bool is_nothrow_invocable_v
> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
> +    = __is_nothrow_invocable(_Fn, _Args...);
> +#else
>      = is_nothrow_invocable<_Fn, _Args...>::value;
> +#endif
>  template<typename _Ret, typename _Fn, typename... _Args>
>    inline constexpr bool is_invocable_r_v
>      = is_invocable_r<_Ret, _Fn, _Args...>::value;
> --
> 2.48.1.131.gda898a5c64
>
Jonathan Wakely March 13, 2025, 5:58 p.m. UTC | #2
On Thu, 6 Mar 2025 at 16:29, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> On Wed, 29 Jan 2025 at 18:55, Patrick Palka wrote:
> >
> > Tested on x86_64-pc-linux-gnu, I suppose this is stage 1 material?
>
> Yes, I think so, since it could impact C++17 programs.
>
> OK for trunk as soon as stage 1 opens though, thanks.

Oh I just realised we're already using the built-in for
is_nothrow_invocable, so this just extends it to the internal
__is_nothrow_invocable and the variable template. Sorry for not
realising the context of this.

So it shouldn't be risky. It's just completing the changes in the
commits you mentioned below.

OK for trunk now, rather than waiting for stage 1.

>
>
> >
> > -- >8 --
> >
> > As a follow-up to r15-1253 and r15-1254.
> >
> > libstdc++-v3/ChangeLog:
> >
> >         * include/std/type_traits (__is_invocable): Define in terms of
> >         corresponding builtin if available.
> >         (__is_nothrow_invocable): Likewise.
> >         (is_invocable_v): Likewise.
> >         (is_nothrow_invocable_v): Likewise.
> > ---
> >  libstdc++-v3/include/std/type_traits | 19 ++++++++++++++++++-
> >  1 file changed, 18 insertions(+), 1 deletion(-)
> >
> > diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> > index 33892818257..f576d5b1426 100644
> > --- a/libstdc++-v3/include/std/type_traits
> > +++ b/libstdc++-v3/include/std/type_traits
> > @@ -3211,7 +3211,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >
> >    template<typename _Fn, typename... _ArgTypes>
> >      struct __is_invocable
> > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
> > +    : __bool_constant<__is_invocable(_Fn, _ArgTypes...)>
> > +#else
> >      : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
> > +#endif
> >      { };
> >
> >    template<typename _Fn, typename _Tp, typename... _Args>
> > @@ -3262,8 +3266,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >    // __is_nothrow_invocable (std::is_nothrow_invocable for C++11)
> >    template<typename _Fn, typename... _Args>
> >      struct __is_nothrow_invocable
> > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
> > +    : __bool_constant<__is_nothrow_invocable(_Fn, _Args...)>
> > +#else
> >      : __and_<__is_invocable<_Fn, _Args...>,
> >               __call_is_nothrow_<_Fn, _Args...>>::type
> > +#endif
> >      { };
> >
> >  #pragma GCC diagnostic push
> > @@ -3702,10 +3710,19 @@ template <typename _From, typename _To>
> >    inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
> >  #endif
> >  template<typename _Fn, typename... _Args>
> > -  inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
> > +  inline constexpr bool is_invocable_v
> > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
> > +    = __is_invocable(_Fn, _Args...);
> > +#else
> > +    = is_invocable<_Fn, _Args...>::value;
> > +#endif
> >  template<typename _Fn, typename... _Args>
> >    inline constexpr bool is_nothrow_invocable_v
> > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
> > +    = __is_nothrow_invocable(_Fn, _Args...);
> > +#else
> >      = is_nothrow_invocable<_Fn, _Args...>::value;
> > +#endif
> >  template<typename _Ret, typename _Fn, typename... _Args>
> >    inline constexpr bool is_invocable_r_v
> >      = is_invocable_r<_Ret, _Fn, _Args...>::value;
> > --
> > 2.48.1.131.gda898a5c64
> >
diff mbox series

Patch

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 33892818257..f576d5b1426 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -3211,7 +3211,11 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template<typename _Fn, typename... _ArgTypes>
     struct __is_invocable
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
+    : __bool_constant<__is_invocable(_Fn, _ArgTypes...)>
+#else
     : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
+#endif
     { };
 
   template<typename _Fn, typename _Tp, typename... _Args>
@@ -3262,8 +3266,12 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // __is_nothrow_invocable (std::is_nothrow_invocable for C++11)
   template<typename _Fn, typename... _Args>
     struct __is_nothrow_invocable
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
+    : __bool_constant<__is_nothrow_invocable(_Fn, _Args...)>
+#else
     : __and_<__is_invocable<_Fn, _Args...>,
              __call_is_nothrow_<_Fn, _Args...>>::type
+#endif
     { };
 
 #pragma GCC diagnostic push
@@ -3702,10 +3710,19 @@  template <typename _From, typename _To>
   inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
 #endif
 template<typename _Fn, typename... _Args>
-  inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
+  inline constexpr bool is_invocable_v
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
+    = __is_invocable(_Fn, _Args...);
+#else
+    = is_invocable<_Fn, _Args...>::value;
+#endif
 template<typename _Fn, typename... _Args>
   inline constexpr bool is_nothrow_invocable_v
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
+    = __is_nothrow_invocable(_Fn, _Args...);
+#else
     = is_nothrow_invocable<_Fn, _Args...>::value;
+#endif
 template<typename _Ret, typename _Fn, typename... _Args>
   inline constexpr bool is_invocable_r_v
     = is_invocable_r<_Ret, _Fn, _Args...>::value;