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.

Signed-off-by: Luc Grosheintz <luc.groshei...@gmail.com>
---
 libstdc++-v3/include/bits/utility.h  | 20 --------------------
 libstdc++-v3/include/std/type_traits | 22 ++++++++++++++++++++++
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/libstdc++-v3/include/bits/utility.h 
b/libstdc++-v3/include/bits/utility.h
index 84d25e0c658..4e574658eba 100644
--- a/libstdc++-v3/include/bits/utility.h
+++ b/libstdc++-v3/include/bits/utility.h
@@ -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
diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index ff23544fbf0..4636457eb5a 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -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
-- 
2.51.0

Reply via email to