From c5fcc3ae39922ed1ab935112c5ffab977ce20087 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Fri, 18 Jul 2025 10:42:30 +0200 Subject: [PATCH] [libc++] Refactor internal index_sequence API to match the public one --- libcxx/include/CMakeLists.txt | 1 - libcxx/include/__functional/bind.h | 21 ++-- .../__memory_resource/polymorphic_allocator.h | 10 +- libcxx/include/__mutex/once_flag.h | 11 +- libcxx/include/__thread/thread.h | 7 +- libcxx/include/__tuple/make_tuple_types.h | 25 ++-- libcxx/include/__tuple/tuple_element.h | 1 - libcxx/include/__tuple/tuple_indices.h | 37 ------ libcxx/include/__utility/integer_sequence.h | 68 +++++------ libcxx/include/__utility/pair.h | 10 +- libcxx/include/bitset | 10 +- libcxx/include/future | 9 +- libcxx/include/module.modulemap.in | 1 - libcxx/include/mutex | 7 +- libcxx/include/scoped_allocator | 10 +- libcxx/include/tuple | 113 +++++++++--------- libcxx/include/variant | 4 +- .../tuple.apply/make_from_tuple.pass.cpp | 2 +- 18 files changed, 139 insertions(+), 208 deletions(-) delete mode 100644 libcxx/include/__tuple/tuple_indices.h diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt index 25b567df2dd33..9bace57c4b7f1 100644 --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -780,7 +780,6 @@ set(files __tuple/make_tuple_types.h __tuple/sfinae_helpers.h __tuple/tuple_element.h - __tuple/tuple_indices.h __tuple/tuple_like.h __tuple/tuple_like_ext.h __tuple/tuple_like_no_subrange.h diff --git a/libcxx/include/__functional/bind.h b/libcxx/include/__functional/bind.h index 596cce03cdb58..def9e4c4ec7a9 100644 --- a/libcxx/include/__functional/bind.h +++ b/libcxx/include/__functional/bind.h @@ -83,15 +83,14 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& __mu(reference_w template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<_Ti&, _Uj...> -__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) { +__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __index_sequence<_Indx...>) { return __ti(std::forward<_Uj>(std::get<_Indx>(__uj))...); } template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<_Ti&, _Uj...> __mu(_Ti& __ti, tuple<_Uj...>& __uj) { - typedef typename __make_tuple_indices::type __indices; - return std::__mu_expand(__ti, __uj, __indices()); + return std::__mu_expand(__ti, __uj, __make_index_sequence()); } template @@ -191,7 +190,7 @@ struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> { template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bind_return<_Fp, _BoundArgs, _Args>::type -__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, _Args&& __args) { +__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __index_sequence<_Indx...>, _Args&& __args) { return std::__invoke(__f, std::__mu(std::get<_Indx>(__bound_args), __args)...); } @@ -205,8 +204,6 @@ class __bind : public __weak_result_type<__decay_t<_Fp> > { _Fd __f_; _Td __bound_args_; - typedef typename __make_tuple_indices::type __indices; - public: template < class _Gp, @@ -219,14 +216,22 @@ class __bind : public __weak_result_type<__decay_t<_Fp> > { template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type operator()(_Args&&... __args) { - return std::__apply_functor(__f_, __bound_args_, __indices(), tuple<_Args&&...>(std::forward<_Args>(__args)...)); + return std::__apply_functor( + __f_, + __bound_args_, + __make_index_sequence(), + tuple<_Args&&...>(std::forward<_Args>(__args)...)); } template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bind_return >::type operator()(_Args&&... __args) const { - return std::__apply_functor(__f_, __bound_args_, __indices(), tuple<_Args&&...>(std::forward<_Args>(__args)...)); + return std::__apply_functor( + __f_, + __bound_args_, + __make_index_sequence(), + tuple<_Args&&...>(std::forward<_Args>(__args)...)); } }; diff --git a/libcxx/include/__memory_resource/polymorphic_allocator.h b/libcxx/include/__memory_resource/polymorphic_allocator.h index 1b8711f10811d..6e7a9afc25deb 100644 --- a/libcxx/include/__memory_resource/polymorphic_allocator.h +++ b/libcxx/include/__memory_resource/polymorphic_allocator.h @@ -135,10 +135,10 @@ class _LIBCPP_AVAILABILITY_PMR polymorphic_allocator { piecewise_construct, __transform_tuple(typename __uses_alloc_ctor< _T1, polymorphic_allocator&, _Args1... >::type(), std::move(__x), - typename __make_tuple_indices::type{}), + make_index_sequence()), __transform_tuple(typename __uses_alloc_ctor< _T2, polymorphic_allocator&, _Args2... >::type(), std::move(__y), - typename __make_tuple_indices::type{})); + make_index_sequence())); } template @@ -194,20 +194,20 @@ class _LIBCPP_AVAILABILITY_PMR polymorphic_allocator { private: template _LIBCPP_HIDE_FROM_ABI tuple<_Args&&...> - __transform_tuple(integral_constant, tuple<_Args...>&& __t, __tuple_indices<_Is...>) { + __transform_tuple(integral_constant, tuple<_Args...>&& __t, index_sequence<_Is...>) { return std::forward_as_tuple(std::get<_Is>(std::move(__t))...); } template _LIBCPP_HIDE_FROM_ABI tuple - __transform_tuple(integral_constant, tuple<_Args...>&& __t, __tuple_indices<_Is...>) { + __transform_tuple(integral_constant, tuple<_Args...>&& __t, index_sequence<_Is...>) { using _Tup = tuple; return _Tup(allocator_arg, *this, std::get<_Is>(std::move(__t))...); } template _LIBCPP_HIDE_FROM_ABI tuple<_Args&&..., polymorphic_allocator&> - __transform_tuple(integral_constant, tuple<_Args...>&& __t, __tuple_indices<_Is...>) { + __transform_tuple(integral_constant, tuple<_Args...>&& __t, index_sequence<_Is...>) { using _Tup = tuple<_Args&&..., polymorphic_allocator&>; return _Tup(std::get<_Is>(std::move(__t))..., *this); } diff --git a/libcxx/include/__mutex/once_flag.h b/libcxx/include/__mutex/once_flag.h index 33064499550eb..e384c15a9f9b6 100644 --- a/libcxx/include/__mutex/once_flag.h +++ b/libcxx/include/__mutex/once_flag.h @@ -13,9 +13,9 @@ #include <__functional/invoke.h> #include <__memory/addressof.h> #include <__memory/shared_count.h> // __libcpp_acquire_load -#include <__tuple/tuple_indices.h> #include <__tuple/tuple_size.h> #include <__utility/forward.h> +#include <__utility/integer_sequence.h> #include <__utility/move.h> #include #ifndef _LIBCPP_CXX03_LANG @@ -87,15 +87,12 @@ class __call_once_param { public: _LIBCPP_HIDE_FROM_ABI explicit __call_once_param(_Fp& __f) : __f_(__f) {} - _LIBCPP_HIDE_FROM_ABI void operator()() { - typedef typename __make_tuple_indices::value, 1>::type _Index; - __execute(_Index()); - } + _LIBCPP_HIDE_FROM_ABI void operator()() { __execute(__make_index_sequence::value>()); } private: template - _LIBCPP_HIDE_FROM_ABI void __execute(__tuple_indices<_Indices...>) { - std::__invoke(std::get<0>(std::move(__f_)), std::get<_Indices>(std::move(__f_))...); + _LIBCPP_HIDE_FROM_ABI void __execute(__index_sequence<_Indices...>) { + std::__invoke(std::get<_Indices>(std::move(__f_))...); } }; diff --git a/libcxx/include/__thread/thread.h b/libcxx/include/__thread/thread.h index 1b51571ce302e..a3b672bc0f0e7 100644 --- a/libcxx/include/__thread/thread.h +++ b/libcxx/include/__thread/thread.h @@ -155,8 +155,8 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id) { # ifndef _LIBCPP_CXX03_LANG template -inline _LIBCPP_HIDE_FROM_ABI void __thread_execute(tuple<_TSp, _Fp, _Args...>& __t, __tuple_indices<_Indices...>) { - std::__invoke(std::move(std::get<1>(__t)), std::move(std::get<_Indices>(__t))...); +inline _LIBCPP_HIDE_FROM_ABI void __thread_execute(tuple<_TSp, _Fp, _Args...>& __t, __index_sequence<_Indices...>) { + std::__invoke(std::move(std::get<_Indices + 1>(__t))...); } template @@ -164,8 +164,7 @@ _LIBCPP_HIDE_FROM_ABI void* __thread_proxy(void* __vp) { // _Fp = tuple< unique_ptr<__thread_struct>, Functor, Args...> unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp)); __thread_local_data().set_pointer(std::get<0>(*__p.get()).release()); - typedef typename __make_tuple_indices::value, 2>::type _Index; - std::__thread_execute(*__p.get(), _Index()); + std::__thread_execute(*__p.get(), __make_index_sequence::value - 1>()); return nullptr; } diff --git a/libcxx/include/__tuple/make_tuple_types.h b/libcxx/include/__tuple/make_tuple_types.h index a5c9bcf23a6eb..3c22ec85dc9c7 100644 --- a/libcxx/include/__tuple/make_tuple_types.h +++ b/libcxx/include/__tuple/make_tuple_types.h @@ -14,12 +14,12 @@ #include <__fwd/array.h> #include <__fwd/tuple.h> #include <__tuple/tuple_element.h> -#include <__tuple/tuple_indices.h> #include <__tuple/tuple_size.h> #include <__tuple/tuple_types.h> #include <__type_traits/copy_cvref.h> #include <__type_traits/remove_cvref.h> #include <__type_traits/remove_reference.h> +#include <__utility/integer_sequence.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -38,38 +38,35 @@ template struct __make_tuple_types_flat; template