]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Merge __type_identity and type_identity for C+20.
authorTomasz Kamiński <tkaminsk@redhat.com>
Thu, 14 May 2026 10:48:19 +0000 (12:48 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Thu, 14 May 2026 14:26:48 +0000 (16:26 +0200)
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 <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
libstdc++-v3/include/std/type_traits

index 1c03c22e8eed4488fe050b915bc3b7b54cccf187..c56fae4a5bf5c36892b803df52abdc1cf0e8171a 100644 (file)
@@ -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<typename _Tp>
+    struct type_identity { using type = _Tp; };
+
+  template<typename _Tp>
+    using type_identity_t = typename type_identity<_Tp>::type;
+  /// @}
+
+  /// @cond undocumented
+  template <typename _Tp>
+    using __type_identity = type_identity<_Tp>;
+
+  template<typename _Tp>
+    using __type_identity_t = typename type_identity<_Tp>::type;
+  /// @endcond
+#else
   /// @cond undocumented
   template <typename _Type>
     struct __type_identity
@@ -171,7 +191,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template<typename _Tp>
     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<typename _Ret, typename _Fn, typename... _Args>
   /// @}
 #endif // __cpp_lib_remove_cvref
 
-#ifdef __cpp_lib_type_identity // C++ >= 20
-  /** * Identity metafunction.
-   * @since C++20
-   * @{
-   */
-  template<typename _Tp>
-    struct type_identity { using type = _Tp; };
-
-  template<typename _Tp>
-    using type_identity_t = typename type_identity<_Tp>::type;
-  /// @}
-#endif
-
 #ifdef __cpp_lib_unwrap_ref // C++ >= 20
   /** Unwrap a reference_wrapper
    * @since C++20