From: Patrick Palka Date: Fri, 16 May 2025 17:06:04 +0000 (-0400) Subject: libstdc++: Use __is_invocable/nothrow_invocable builtins more X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=259154325688cbfe6d3b50e91dbd6b997a969d6d;p=thirdparty%2Fgcc.git libstdc++: Use __is_invocable/nothrow_invocable builtins more As a follow-up to r15-1253 and r15-1254 which made us use these builtins in the standard std::is_invocable/nothrow_invocable class templates, let's also use them directly in the standard variable templates and our internal C++11 __is_invocable/nothrow_invocable class templates. 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. Reviewed-by: Jonathan Wakely --- diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 676cdf2d7e6..0601869266c 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3212,7 +3212,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template 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 @@ -3263,8 +3267,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // __is_nothrow_invocable (std::is_nothrow_invocable for C++11) template 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 @@ -3704,10 +3712,19 @@ template inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value; #endif template - 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 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 inline constexpr bool is_invocable_r_v = is_invocable_r<_Ret, _Fn, _Args...>::value;