From 8cf3c99b5a89a8b775907094a34c25d3ed88ab72 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Sun, 9 Nov 2025 11:49:09 +0100 Subject: [PATCH] [libc++] Simplify a few places where we use --- libcxx/include/__functional/bind.h | 20 +++++------------ libcxx/include/__mutex/once_flag.h | 10 ++++----- libcxx/include/__utility/integer_sequence.h | 3 +++ libcxx/include/__utility/pair.h | 6 +---- libcxx/include/future | 10 ++++----- libcxx/include/scoped_allocator | 4 ++-- libcxx/include/tuple | 25 +++++++++------------ 7 files changed, 30 insertions(+), 48 deletions(-) diff --git a/libcxx/include/__functional/bind.h b/libcxx/include/__functional/bind.h index def9e4c4ec7a9..2793cac743f88 100644 --- a/libcxx/include/__functional/bind.h +++ b/libcxx/include/__functional/bind.h @@ -81,16 +81,12 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& __mu(reference_w return __t.get(); } -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<_Ti&, _Uj...> -__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) { - return std::__mu_expand(__ti, __uj, __make_index_sequence()); + return [&](__index_sequence<_Indices...>) { + return __ti(std::forward<_Uj>(std::get<_Indices>(__uj))...); + }(__index_sequence_for<_Uj...>{}); } template @@ -217,10 +213,7 @@ class __bind : public __weak_result_type<__decay_t<_Fp> > { _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_, - __make_index_sequence(), - tuple<_Args&&...>(std::forward<_Args>(__args)...)); + __f_, __bound_args_, __index_sequence_for<_BoundArgs...>(), tuple<_Args&&...>(std::forward<_Args>(__args)...)); } template @@ -228,10 +221,7 @@ class __bind : public __weak_result_type<__decay_t<_Fp> > { typename __bind_return >::type operator()(_Args&&... __args) const { return std::__apply_functor( - __f_, - __bound_args_, - __make_index_sequence(), - tuple<_Args&&...>(std::forward<_Args>(__args)...)); + __f_, __bound_args_, __index_sequence_for<_BoundArgs...>(), tuple<_Args&&...>(std::forward<_Args>(__args)...)); } }; diff --git a/libcxx/include/__mutex/once_flag.h b/libcxx/include/__mutex/once_flag.h index 808b1ea99cc0b..2c53d072a5194 100644 --- a/libcxx/include/__mutex/once_flag.h +++ b/libcxx/include/__mutex/once_flag.h @@ -86,12 +86,10 @@ class __call_once_param { public: _LIBCPP_HIDE_FROM_ABI explicit __call_once_param(_Fp& __f) : __f_(__f) {} - _LIBCPP_HIDE_FROM_ABI void operator()() { __execute(__make_index_sequence::value>()); } - -private: - template - _LIBCPP_HIDE_FROM_ABI void __execute(__index_sequence<_Indices...>) { - std::__invoke(std::get<_Indices>(std::move(__f_))...); + _LIBCPP_HIDE_FROM_ABI void operator()() { + [&](__index_sequence<_Indices...>) { + std::__invoke(std::get<_Indices>(std::move(__f_))...); + }(__make_index_sequence::value>()); } }; diff --git a/libcxx/include/__utility/integer_sequence.h b/libcxx/include/__utility/integer_sequence.h index 329826ae5eda2..fe8773ab73165 100644 --- a/libcxx/include/__utility/integer_sequence.h +++ b/libcxx/include/__utility/integer_sequence.h @@ -42,6 +42,9 @@ using __index_sequence _LIBCPP_NODEBUG = __integer_sequence template using __make_index_sequence _LIBCPP_NODEBUG = __make_integer_sequence_impl<__integer_sequence, size_t, _SequenceSize>; +template +using __index_sequence_for _LIBCPP_NODEBUG = __make_index_sequence; + # if _LIBCPP_STD_VER >= 14 template diff --git a/libcxx/include/__utility/pair.h b/libcxx/include/__utility/pair.h index 33694c52430f1..32c8ea9db66d6 100644 --- a/libcxx/include/__utility/pair.h +++ b/libcxx/include/__utility/pair.h @@ -222,11 +222,7 @@ struct pair _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) noexcept( is_nothrow_constructible::value && is_nothrow_constructible::value) - : pair(__pc, - __first_args, - __second_args, - __make_index_sequence(), - __make_index_sequence()) {} + : pair(__pc, __first_args, __second_args, __index_sequence_for<_Args1...>(), __index_sequence_for<_Args2...>()) {} _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=(__conditional_t::value && is_copy_assignable::value, diff --git a/libcxx/include/future b/libcxx/include/future index 4b7c09841cbd3..5f25f21a3d2e0 100644 --- a/libcxx/include/future +++ b/libcxx/include/future @@ -1836,12 +1836,10 @@ public: _LIBCPP_HIDE_FROM_ABI __async_func(__async_func&& __f) : __f_(std::move(__f.__f_)) {} - _LIBCPP_HIDE_FROM_ABI _Rp operator()() { return __execute(__make_index_sequence()); } - -private: - template - _LIBCPP_HIDE_FROM_ABI _Rp __execute(__index_sequence<_Indices...>) { - return std::__invoke(std::move(std::get<_Indices>(__f_))...); + _LIBCPP_HIDE_FROM_ABI _Rp operator()() { + return [&](__index_sequence<_Indices>...) { + return std::__invoke(std::move(std::get<_Indices>(__f_))...); + }(__index_sequence_for<_Fp, _Args...>{}); } }; diff --git a/libcxx/include/scoped_allocator b/libcxx/include/scoped_allocator index 74effc547f3e2..c72c470f0c541 100644 --- a/libcxx/include/scoped_allocator +++ b/libcxx/include/scoped_allocator @@ -434,10 +434,10 @@ public: piecewise_construct, __transform_tuple(typename __uses_alloc_ctor< _T1, inner_allocator_type&, _Args1... >::type(), std::move(__x), - __make_index_sequence()), + __index_sequence_for<_Args1...>()), __transform_tuple(typename __uses_alloc_ctor< _T2, inner_allocator_type&, _Args2... >::type(), std::move(__y), - __make_index_sequence())); + __index_sequence_for<_Args2...>())); } template diff --git a/libcxx/include/tuple b/libcxx/include/tuple index 0cfcd9a4fd9c5..b9fe20053eb90 100644 --- a/libcxx/include/tuple +++ b/libcxx/include/tuple @@ -577,7 +577,7 @@ __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __type_list<_Up.. template class _LIBCPP_NO_SPECIALIZATIONS tuple { - typedef __tuple_impl<__make_index_sequence, _Tp...> _BaseT; + typedef __tuple_impl<__index_sequence_for<_Tp...>, _Tp...> _BaseT; _BaseT __base_; @@ -860,7 +860,7 @@ public: _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(_If<_And...>::value, tuple, __nat> const& __tuple) noexcept( _And...>::value) { - std::__memberwise_copy_assign(*this, __tuple, __make_index_sequence()); + std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>()); return *this; } @@ -868,15 +868,14 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple const& __tuple) const requires(_And...>::value) { - std::__memberwise_copy_assign(*this, __tuple, __make_index_sequence()); + std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>()); return *this; } _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple&& __tuple) const requires(_And...>::value) { - std::__memberwise_forward_assign( - *this, std::move(__tuple), __type_list<_Tp...>(), __make_index_sequence()); + std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Tp...>(), __index_sequence_for<_Tp...>()); return *this; } # endif // _LIBCPP_STD_VER >= 23 @@ -884,8 +883,7 @@ public: _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(_If<_And...>::value, tuple, __nat>&& __tuple) noexcept( _And...>::value) { - std::__memberwise_forward_assign( - *this, std::move(__tuple), __type_list<_Tp...>(), __make_index_sequence()); + std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Tp...>(), __index_sequence_for<_Tp...>()); return *this; } @@ -895,7 +893,7 @@ public: int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(tuple<_Up...> const& __tuple) noexcept(_And...>::value) { - std::__memberwise_copy_assign(*this, __tuple, __make_index_sequence()); + std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>()); return *this; } @@ -904,8 +902,7 @@ public: int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(tuple<_Up...>&& __tuple) noexcept(_And...>::value) { - std::__memberwise_forward_assign( - *this, std::move(__tuple), __type_list<_Up...>(), __make_index_sequence()); + std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Up...>(), __index_sequence_for<_Tp...>()); return *this; } @@ -914,7 +911,7 @@ public: enable_if_t< _And<_BoolConstant, is_assignable...>::value>* = nullptr> _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const tuple<_UTypes...>& __u) const { - std::__memberwise_copy_assign(*this, __u, __make_index_sequence()); + std::__memberwise_copy_assign(*this, __u, index_sequence_for<_Tp...>()); return *this; } @@ -922,7 +919,7 @@ public: enable_if_t< _And<_BoolConstant, is_assignable...>::value>* = nullptr> _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple<_UTypes...>&& __u) const { - std::__memberwise_forward_assign(*this, __u, __type_list<_UTypes...>(), __make_index_sequence()); + std::__memberwise_forward_assign(*this, __u, __type_list<_UTypes...>(), index_sequence_for<_Tp...>()); return *this; } # endif // _LIBCPP_STD_VER >= 23 @@ -988,7 +985,7 @@ public: __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up const&>... >::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(array<_Up, _Np> const& __array) noexcept(_And...>::value) { - std::__memberwise_copy_assign(*this, __array, __make_index_sequence()); + std::__memberwise_copy_assign(*this, __array, __index_sequence_for<_Tp...>()); return *this; } @@ -1000,7 +997,7 @@ public: _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(array<_Up, _Np>&& __array) noexcept(_And...>::value) { std::__memberwise_forward_assign( - *this, std::move(__array), __type_list<_If...>(), __make_index_sequence()); + *this, std::move(__array), __type_list<_If...>(), __index_sequence_for<_Tp...>()); return *this; }