On Tue, 3 Jun 2025 at 10:54, Tomasz Kaminski wrote: > > > > On Mon, Jun 2, 2025 at 10:56 PM Jonathan Wakely <jwak...@redhat.com> wrote: >> >> libstdc++-v3/ChangeLog: >> >> * include/std/type_traits (is_destructible, is_destructible_v): >> Define using new built-in. >> (is_nothrow_destructible, is_nothrow_destructible_v): Likewise. >> (is_trivially_destructible, is_trivially_destructible_v): >> Likewise. >> --- >> >> Thanks to Jason's latest fixes, the new built-in now allows us to >> replace the complicated class templates that implement these traits. >> >> Tested x86_64-linux. > > LGTM. I wouldn't think about updating variable traits.
Implementing the variable templates directly in terms of the built-in means not instantiating any class template for those variables, which is a small but significant speedup. >> >> >> libstdc++-v3/include/std/type_traits | 42 ++++++++++++++++++++++++++-- >> 1 file changed, 40 insertions(+), 2 deletions(-) >> >> diff --git a/libstdc++-v3/include/std/type_traits >> b/libstdc++-v3/include/std/type_traits >> index 6bf355d97cc9..c8907fe4d382 100644 >> --- a/libstdc++-v3/include/std/type_traits >> +++ b/libstdc++-v3/include/std/type_traits >> @@ -1039,6 +1039,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION >> >> // Destructible and constructible type properties. >> >> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_destructible) >> + /// is_destructible >> + template<typename _Tp> >> + struct is_destructible >> + : public __bool_constant<__is_destructible(_Tp)> >> + { }; >> +#else >> // In N3290 is_destructible does not say anything about function >> // types and abstract types, see LWG 2049. This implementation >> // describes function types as non-destructible and all complete >> @@ -1090,7 +1097,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION >> static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}), >> "template argument must be a complete class or an unbounded array"); >> }; >> +#endif >> >> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_destructible) >> + /// is_nothrow_destructible >> + template<typename _Tp> >> + struct is_nothrow_destructible >> + : public __bool_constant<__is_nothrow_destructible(_Tp)> >> + { }; >> +#else >> /// @cond undocumented >> >> // is_nothrow_destructible requires that is_destructible is >> @@ -1144,6 +1159,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION >> static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}), >> "template argument must be a complete class or an unbounded array"); >> }; >> +#endif >> >> /// @cond undocumented >> template<typename _Tp, typename... _Args> >> @@ -1451,6 +1467,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION >> "template argument must be a complete class or an unbounded array"); >> }; >> >> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_trivially_destructible) >> + /// is_trivially_destructible >> + template<typename _Tp> >> + struct is_trivially_destructible >> + : public __bool_constant<__is_trivially_destructible(_Tp)> >> + { }; >> +#else >> /// is_trivially_destructible >> template<typename _Tp> >> struct is_trivially_destructible >> @@ -1460,7 +1483,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION >> static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}), >> "template argument must be a complete class or an unbounded array"); >> }; >> - >> +#endif >> >> /// has_virtual_destructor >> template<typename _Tp> >> @@ -3581,8 +3604,13 @@ template <typename _Tp> >> inline constexpr bool is_move_assignable_v >> = __is_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>); >> >> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_destructible) >> +template <typename _Tp> >> + inline constexpr bool is_destructible_v = __is_destructible(_Tp); >> +#else >> template <typename _Tp> >> inline constexpr bool is_destructible_v = is_destructible<_Tp>::value; >> +#endif >> >> template <typename _Tp, typename... _Args> >> inline constexpr bool is_trivially_constructible_v >> @@ -3609,7 +3637,11 @@ template <typename _Tp> >> = __is_trivially_assignable(__add_lval_ref_t<_Tp>, >> __add_rval_ref_t<_Tp>); >> >> -#if __cpp_concepts >> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_trivially_destructible) >> +template <typename _Tp> >> + inline constexpr bool is_trivially_destructible_v >> + = __is_trivially_destructible(_Tp); >> +#elif __cpp_concepts >> template <typename _Tp> >> inline constexpr bool is_trivially_destructible_v = false; >> >> @@ -3654,9 +3686,15 @@ template <typename _Tp> >> inline constexpr bool is_nothrow_move_assignable_v >> = __is_nothrow_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>); >> >> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_destructible) >> +template <typename _Tp> >> + inline constexpr bool is_nothrow_destructible_v >> + = __is_nothrow_destructible(_Tp); >> +#else >> template <typename _Tp> >> inline constexpr bool is_nothrow_destructible_v = >> is_nothrow_destructible<_Tp>::value; >> +#endif >> >> template <typename _Tp> >> inline constexpr bool has_virtual_destructor_v >> -- >> 2.49.0 >>