]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Move _Index_tuple, _Build_index_tuple to <type_traits>.
authorLuc Grosheintz <luc.grosheintz@gmail.com>
Tue, 2 Sep 2025 07:59:44 +0000 (09:59 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Tue, 2 Sep 2025 11:27:45 +0000 (13:27 +0200)
As preparation for implementing std::constant_wrapper that's part of the
C++26 version of the <type_traits> header, the two classes _Index_tuple
and _Build_index_tuple are moved to <type_traits>. These two helpers are
needed by std::constant_wrapper to initialize the elements of one C
array with another.

Since, <bits/utility.h> already includes <type_traits> this solution
avoids creating a very small header file for just these two internal
classes. This approach doesn't move std::index_sequence and related code
to <type_traits> and therefore doesn't change which headers provide
user-facing features.

libstdc++-v3/ChangeLog:

* include/bits/utility.h (_Index_tuple): Move to <type_traits>.
(_Build_index_tuple): Ditto.
* include/std/type_traits (_Index_tuple): Ditto.
(_Build_index_tuple): Ditto.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
libstdc++-v3/include/bits/utility.h
libstdc++-v3/include/std/type_traits

index 84d25e0c658066a094d5806fc61dd877cd43a089..4e574658eba598d6e55f016d5e5ba34f09db6bd2 100644 (file)
@@ -137,26 +137,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     using tuple_element_t = typename tuple_element<__i, _Tp>::type;
 #endif
 
-  // Stores a tuple of indices.  Used by tuple and pair, and by bind() to
-  // extract the elements in a tuple.
-  template<size_t... _Indexes> struct _Index_tuple { };
-
-  // Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
-  template<size_t _Num>
-    struct _Build_index_tuple
-    {
-#if __has_builtin(__make_integer_seq)
-      template<typename, size_t... _Indices>
-       using _IdxTuple = _Index_tuple<_Indices...>;
-
-      // Clang defines __make_integer_seq for this purpose.
-      using __type = __make_integer_seq<_IdxTuple, size_t, _Num>;
-#else
-      // For GCC and other compilers, use __integer_pack instead.
-      using __type = _Index_tuple<__integer_pack(_Num)...>;
-#endif
-    };
-
 #ifdef __glibcxx_integer_sequence // C++ >= 14
 
   /// Class template integer_sequence
index ff23544fbf0311279e838cf29e8a47af98e98afe..4636457eb5a45cb4d56d3aaffc19ebdd75eff052 100644 (file)
@@ -4280,6 +4280,28 @@ template<typename _Ret, typename _Fn, typename... _Args>
 
 #endif // C++2a
 
+#if __cplusplus >= 201103L
+  // Stores a tuple of indices.  Used by tuple and pair, and by bind() to
+  // extract the elements in a tuple.
+  template<size_t... _Indexes> struct _Index_tuple { };
+
+  // Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
+  template<size_t _Num>
+    struct _Build_index_tuple
+    {
+#if __has_builtin(__make_integer_seq)
+      template<typename, size_t... _Indices>
+       using _IdxTuple = _Index_tuple<_Indices...>;
+
+      // Clang defines __make_integer_seq for this purpose.
+      using __type = __make_integer_seq<_IdxTuple, size_t, _Num>;
+#else
+      // For GCC and other compilers, use __integer_pack instead.
+      using __type = _Index_tuple<__integer_pack(_Num)...>;
+#endif
+    };
+#endif // C++11
+
   /// @} group metaprogramming
 
 _GLIBCXX_END_NAMESPACE_VERSION