Skip to content

Commit 9ff05e3

Browse files
committed
[libc++] Simplify a few places where we use
1 parent ac4cf40 commit 9ff05e3

File tree

7 files changed

+30
-48
lines changed

7 files changed

+30
-48
lines changed

libcxx/include/__functional/bind.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,12 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& __mu(reference_w
8181
return __t.get();
8282
}
8383

84-
template <class _Ti, class... _Uj, size_t... _Indx>
85-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<_Ti&, _Uj...>
86-
__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __index_sequence<_Indx...>) {
87-
return __ti(std::forward<_Uj>(std::get<_Indx>(__uj))...);
88-
}
89-
9084
template <class _Ti, class... _Uj, __enable_if_t<is_bind_expression<_Ti>::value, int> = 0>
9185
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<_Ti&, _Uj...>
9286
__mu(_Ti& __ti, tuple<_Uj...>& __uj) {
93-
return std::__mu_expand(__ti, __uj, __make_index_sequence<sizeof...(_Uj)>());
87+
return [&]<size_t... _Indices>(__index_sequence<_Indices...>) {
88+
return __ti(std::forward<_Uj>(std::get<_Indices>(__uj))...);
89+
}(__index_sequence_for<_Uj...>{});
9490
}
9591

9692
template <bool _IsPh, class _Ti, class _Uj>
@@ -217,21 +213,15 @@ class __bind : public __weak_result_type<__decay_t<_Fp> > {
217213
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
218214
operator()(_Args&&... __args) {
219215
return std::__apply_functor(
220-
__f_,
221-
__bound_args_,
222-
__make_index_sequence<sizeof...(_BoundArgs)>(),
223-
tuple<_Args&&...>(std::forward<_Args>(__args)...));
216+
__f_, __bound_args_, __index_sequence_for<_BoundArgs...>(), tuple<_Args&&...>(std::forward<_Args>(__args)...));
224217
}
225218

226219
template <class... _Args>
227220
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
228221
typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
229222
operator()(_Args&&... __args) const {
230223
return std::__apply_functor(
231-
__f_,
232-
__bound_args_,
233-
__make_index_sequence<sizeof...(_BoundArgs)>(),
234-
tuple<_Args&&...>(std::forward<_Args>(__args)...));
224+
__f_, __bound_args_, __index_sequence_for<_BoundArgs...>(), tuple<_Args&&...>(std::forward<_Args>(__args)...));
235225
}
236226
};
237227

libcxx/include/__mutex/once_flag.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,10 @@ class __call_once_param {
8686
public:
8787
_LIBCPP_HIDE_FROM_ABI explicit __call_once_param(_Fp& __f) : __f_(__f) {}
8888

89-
_LIBCPP_HIDE_FROM_ABI void operator()() { __execute(__make_index_sequence<tuple_size<_Fp>::value>()); }
90-
91-
private:
92-
template <size_t... _Indices>
93-
_LIBCPP_HIDE_FROM_ABI void __execute(__index_sequence<_Indices...>) {
94-
std::__invoke(std::get<_Indices>(std::move(__f_))...);
89+
_LIBCPP_HIDE_FROM_ABI void operator()() {
90+
[&]<size_t... _Indices>(__index_sequence<_Indices...>) -> void {
91+
std::__invoke(std::get<_Indices>(std::move(__f_))...);
92+
}(__make_index_sequence<tuple_size<_Fp>::value>());
9593
}
9694
};
9795

libcxx/include/__utility/integer_sequence.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ using __index_sequence _LIBCPP_NODEBUG = __integer_sequence<size_t, _Indices...>
4242
template <size_t _SequenceSize>
4343
using __make_index_sequence _LIBCPP_NODEBUG = __make_integer_sequence_impl<__integer_sequence, size_t, _SequenceSize>;
4444

45+
template <class... _Args>
46+
using __index_sequence_for _LIBCPP_NODEBUG = __make_index_sequence<sizeof...(_Args)>;
47+
4548
# if _LIBCPP_STD_VER >= 14
4649

4750
template <class _Tp, _Tp... _Indices>

libcxx/include/__utility/pair.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,7 @@ struct pair
219219
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
220220
pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) noexcept(
221221
is_nothrow_constructible<first_type, _Args1...>::value && is_nothrow_constructible<second_type, _Args2...>::value)
222-
: pair(__pc,
223-
__first_args,
224-
__second_args,
225-
__make_index_sequence<sizeof...(_Args1)>(),
226-
__make_index_sequence<sizeof...(_Args2)>()) {}
222+
: pair(__pc, __first_args, __second_args, __index_sequence_for<_Args1...>(), __index_sequence_for<_Args2...>()) {}
227223

228224
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair&
229225
operator=(__conditional_t<is_copy_assignable<first_type>::value && is_copy_assignable<second_type>::value,

libcxx/include/future

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,12 +1833,10 @@ public:
18331833

18341834
_LIBCPP_HIDE_FROM_ABI __async_func(__async_func&& __f) : __f_(std::move(__f.__f_)) {}
18351835

1836-
_LIBCPP_HIDE_FROM_ABI _Rp operator()() { return __execute(__make_index_sequence<sizeof...(_Args) + 1>()); }
1837-
1838-
private:
1839-
template <size_t... _Indices>
1840-
_LIBCPP_HIDE_FROM_ABI _Rp __execute(__index_sequence<_Indices...>) {
1841-
return std::__invoke(std::move(std::get<_Indices>(__f_))...);
1836+
_LIBCPP_HIDE_FROM_ABI _Rp operator()() {
1837+
return [&]<size_t... _Indices>(__index_sequence<_Indices...>) -> _Rp {
1838+
return std::__invoke(std::move(std::get<_Indices>(__f_))...);
1839+
}(__index_sequence_for<_Fp, _Args...>{});
18421840
}
18431841
};
18441842

libcxx/include/scoped_allocator

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,10 @@ public:
434434
piecewise_construct,
435435
__transform_tuple(typename __uses_alloc_ctor< _T1, inner_allocator_type&, _Args1... >::type(),
436436
std::move(__x),
437-
__make_index_sequence<sizeof...(_Args1)>()),
437+
__index_sequence_for<_Args1...>()),
438438
__transform_tuple(typename __uses_alloc_ctor< _T2, inner_allocator_type&, _Args2... >::type(),
439439
std::move(__y),
440-
__make_index_sequence<sizeof...(_Args2)>()));
440+
__index_sequence_for<_Args2...>()));
441441
}
442442

443443
template <class _T1, class _T2>

libcxx/include/tuple

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __type_list<_Up..
576576

577577
template <class... _Tp>
578578
class _LIBCPP_NO_SPECIALIZATIONS tuple {
579-
typedef __tuple_impl<__make_index_sequence<sizeof...(_Tp)>, _Tp...> _BaseT;
579+
typedef __tuple_impl<__index_sequence_for<_Tp...>, _Tp...> _BaseT;
580580

581581
_BaseT __base_;
582582

@@ -858,32 +858,30 @@ public:
858858
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
859859
operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple) noexcept(
860860
_And<is_nothrow_copy_assignable<_Tp>...>::value) {
861-
std::__memberwise_copy_assign(*this, __tuple, __make_index_sequence<sizeof...(_Tp)>());
861+
std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>());
862862
return *this;
863863
}
864864

865865
# if _LIBCPP_STD_VER >= 23
866866
_LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple const& __tuple) const
867867
requires(_And<is_copy_assignable<const _Tp>...>::value)
868868
{
869-
std::__memberwise_copy_assign(*this, __tuple, __make_index_sequence<sizeof...(_Tp)>());
869+
std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>());
870870
return *this;
871871
}
872872

873873
_LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple&& __tuple) const
874874
requires(_And<is_assignable<const _Tp&, _Tp>...>::value)
875875
{
876-
std::__memberwise_forward_assign(
877-
*this, std::move(__tuple), __type_list<_Tp...>(), __make_index_sequence<sizeof...(_Tp)>());
876+
std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Tp...>(), __index_sequence_for<_Tp...>());
878877
return *this;
879878
}
880879
# endif // _LIBCPP_STD_VER >= 23
881880

882881
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
883882
operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple) noexcept(
884883
_And<is_nothrow_move_assignable<_Tp>...>::value) {
885-
std::__memberwise_forward_assign(
886-
*this, std::move(__tuple), __type_list<_Tp...>(), __make_index_sequence<sizeof...(_Tp)>());
884+
std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Tp...>(), __index_sequence_for<_Tp...>());
887885
return *this;
888886
}
889887

@@ -893,7 +891,7 @@ public:
893891
int> = 0>
894892
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
895893
operator=(tuple<_Up...> const& __tuple) noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
896-
std::__memberwise_copy_assign(*this, __tuple, __make_index_sequence<sizeof...(_Tp)>());
894+
std::__memberwise_copy_assign(*this, __tuple, __index_sequence_for<_Tp...>());
897895
return *this;
898896
}
899897

@@ -902,8 +900,7 @@ public:
902900
int> = 0>
903901
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
904902
operator=(tuple<_Up...>&& __tuple) noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
905-
std::__memberwise_forward_assign(
906-
*this, std::move(__tuple), __type_list<_Up...>(), __make_index_sequence<sizeof...(_Tp)>());
903+
std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Up...>(), __index_sequence_for<_Tp...>());
907904
return *this;
908905
}
909906

@@ -912,15 +909,15 @@ public:
912909
enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
913910
is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr>
914911
_LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const tuple<_UTypes...>& __u) const {
915-
std::__memberwise_copy_assign(*this, __u, __make_index_sequence<sizeof...(_Tp)>());
912+
std::__memberwise_copy_assign(*this, __u, index_sequence_for<_Tp...>());
916913
return *this;
917914
}
918915

919916
template <class... _UTypes,
920917
enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
921918
is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr>
922919
_LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple<_UTypes...>&& __u) const {
923-
std::__memberwise_forward_assign(*this, __u, __type_list<_UTypes...>(), __make_index_sequence<sizeof...(_Tp)>());
920+
std::__memberwise_forward_assign(*this, __u, __type_list<_UTypes...>(), index_sequence_for<_Tp...>());
924921
return *this;
925922
}
926923
# endif // _LIBCPP_STD_VER >= 23
@@ -986,7 +983,7 @@ public:
986983
__enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up const&>... >::value, int> = 0>
987984
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
988985
operator=(array<_Up, _Np> const& __array) noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
989-
std::__memberwise_copy_assign(*this, __array, __make_index_sequence<sizeof...(_Tp)>());
986+
std::__memberwise_copy_assign(*this, __array, __index_sequence_for<_Tp...>());
990987
return *this;
991988
}
992989

@@ -998,7 +995,7 @@ public:
998995
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
999996
operator=(array<_Up, _Np>&& __array) noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
1000997
std::__memberwise_forward_assign(
1001-
*this, std::move(__array), __type_list<_If<true, _Up, _Tp>...>(), __make_index_sequence<sizeof...(_Tp)>());
998+
*this, std::move(__array), __type_list<_If<true, _Up, _Tp>...>(), __index_sequence_for<_Tp...>());
1002999
return *this;
10031000
}
10041001

0 commit comments

Comments
 (0)