From: Tomasz Kamiński Date: Thu, 14 May 2026 10:48:19 +0000 (+0200) Subject: libstdc++: Merge __type_identity and type_identity for C+20. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1283fc2e30965ea57965bb5ad19f221a645f9c7e;p=thirdparty%2Fgcc.git libstdc++: Merge __type_identity and type_identity for C+20. The components that used __type_identity in C++20 mode (due source compatibility with older standard) lead to instantiation of separate class template from std::type_identity for each used type. This patch makes __type_identity an alias to type_identity if the latter is available. libstdc++-v3/ChangeLog: * include/std/type_traits (__type_identity, __type_identity_t) [__cpp_lib_type_identity]: Define as alias to type_identity and its nested type respectively. Reviewed-by: Jonathan Wakely Signed-off-by: Tomasz Kamiński --- diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 1c03c22e8ee..c56fae4a5bf 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -164,6 +164,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __conditional_t = typename __conditional<_Cond>::template type<_If, _Else>; +#ifdef __cpp_lib_type_identity // C++ >= 20 + /** Identity metafunction. + * @since C++20 + * @{ + */ + template + struct type_identity { using type = _Tp; }; + + template + using type_identity_t = typename type_identity<_Tp>::type; + /// @} + + /// @cond undocumented + template + using __type_identity = type_identity<_Tp>; + + template + using __type_identity_t = typename type_identity<_Tp>::type; + /// @endcond +#else /// @cond undocumented template struct __type_identity @@ -171,7 +191,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template using __type_identity_t = typename __type_identity<_Tp>::type; + /// @endcond +#endif + /// @cond undocumented namespace __detail { // A variadic alias template that resolves to its first argument. @@ -3955,19 +3978,6 @@ template /// @} #endif // __cpp_lib_remove_cvref -#ifdef __cpp_lib_type_identity // C++ >= 20 - /** * Identity metafunction. - * @since C++20 - * @{ - */ - template - struct type_identity { using type = _Tp; }; - - template - using type_identity_t = typename type_identity<_Tp>::type; - /// @} -#endif - #ifdef __cpp_lib_unwrap_ref // C++ >= 20 /** Unwrap a reference_wrapper * @since C++20