Skip to content

Commit fd6619a

Browse files
committed
[libc++] Simplify a few places where we use
1 parent 0b52b82 commit fd6619a

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...>) {
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
@@ -222,11 +222,7 @@ struct pair
222222
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
223223
pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) noexcept(
224224
is_nothrow_constructible<first_type, _Args1...>::value && is_nothrow_constructible<second_type, _Args2...>::value)
225-
: pair(__pc,
226-
__first_args,
227-
__second_args,
228-
__make_index_sequence<sizeof...(_Args1)>(),
229-
__make_index_sequence<sizeof...(_Args2)>()) {}
225+
: pair(__pc, __first_args, __second_args, __index_sequence_for<_Args1...>(), __index_sequence_for<_Args2...>()) {}
230226

231227
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair&
232228
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
@@ -1836,12 +1836,10 @@ public:
18361836

18371837
_LIBCPP_HIDE_FROM_ABI __async_func(__async_func&& __f) : __f_(std::move(__f.__f_)) {}
18381838

1839-
_LIBCPP_HIDE_FROM_ABI _Rp operator()() { return __execute(__make_index_sequence<sizeof...(_Args) + 1>()); }
1840-
1841-
private:
1842-
template <size_t... _Indices>
1843-
_LIBCPP_HIDE_FROM_ABI _Rp __execute(__index_sequence<_Indices...>) {
1844-
return std::__invoke(std::move(std::get<_Indices>(__f_))...);
1839+
_LIBCPP_HIDE_FROM_ABI _Rp operator()() {
1840+
return [&]<size_t... _Indices>(__index_sequence<_Indices...>) {
1841+
return std::__invoke(std::move(std::get<_Indices>(__f_))...);
1842+
}(__index_sequence_for<_Fp, _Args...>{});
18451843
}
18461844
};
18471845

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
@@ -577,7 +577,7 @@ __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __type_list<_Up..
577577

578578
template <class... _Tp>
579579
class _LIBCPP_NO_SPECIALIZATIONS tuple {
580-
typedef __tuple_impl<__make_index_sequence<sizeof...(_Tp)>, _Tp...> _BaseT;
580+
typedef __tuple_impl<__index_sequence_for<_Tp...>, _Tp...> _BaseT;
581581

582582
_BaseT __base_;
583583

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

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

875875
_LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple&& __tuple) const
876876
requires(_And<is_assignable<const _Tp&, _Tp>...>::value)
877877
{
878-
std::__memberwise_forward_assign(
879-
*this, std::move(__tuple), __type_list<_Tp...>(), __make_index_sequence<sizeof...(_Tp)>());
878+
std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Tp...>(), __index_sequence_for<_Tp...>());
880879
return *this;
881880
}
882881
# endif // _LIBCPP_STD_VER >= 23
883882

884883
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
885884
operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple) noexcept(
886885
_And<is_nothrow_move_assignable<_Tp>...>::value) {
887-
std::__memberwise_forward_assign(
888-
*this, std::move(__tuple), __type_list<_Tp...>(), __make_index_sequence<sizeof...(_Tp)>());
886+
std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Tp...>(), __index_sequence_for<_Tp...>());
889887
return *this;
890888
}
891889

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

@@ -904,8 +902,7 @@ public:
904902
int> = 0>
905903
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
906904
operator=(tuple<_Up...>&& __tuple) noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
907-
std::__memberwise_forward_assign(
908-
*this, std::move(__tuple), __type_list<_Up...>(), __make_index_sequence<sizeof...(_Tp)>());
905+
std::__memberwise_forward_assign(*this, std::move(__tuple), __type_list<_Up...>(), __index_sequence_for<_Tp...>());
909906
return *this;
910907
}
911908

@@ -914,15 +911,15 @@ public:
914911
enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
915912
is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr>
916913
_LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const tuple<_UTypes...>& __u) const {
917-
std::__memberwise_copy_assign(*this, __u, __make_index_sequence<sizeof...(_Tp)>());
914+
std::__memberwise_copy_assign(*this, __u, index_sequence_for<_Tp...>());
918915
return *this;
919916
}
920917

921918
template <class... _UTypes,
922919
enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
923920
is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr>
924921
_LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple<_UTypes...>&& __u) const {
925-
std::__memberwise_forward_assign(*this, __u, __type_list<_UTypes...>(), __make_index_sequence<sizeof...(_Tp)>());
922+
std::__memberwise_forward_assign(*this, __u, __type_list<_UTypes...>(), index_sequence_for<_Tp...>());
926923
return *this;
927924
}
928925
# endif // _LIBCPP_STD_VER >= 23
@@ -988,7 +985,7 @@ public:
988985
__enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up const&>... >::value, int> = 0>
989986
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
990987
operator=(array<_Up, _Np> const& __array) noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
991-
std::__memberwise_copy_assign(*this, __array, __make_index_sequence<sizeof...(_Tp)>());
988+
std::__memberwise_copy_assign(*this, __array, __index_sequence_for<_Tp...>());
992989
return *this;
993990
}
994991

@@ -1000,7 +997,7 @@ public:
1000997
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
1001998
operator=(array<_Up, _Np>&& __array) noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
1002999
std::__memberwise_forward_assign(
1003-
*this, std::move(__array), __type_list<_If<true, _Up, _Tp>...>(), __make_index_sequence<sizeof...(_Tp)>());
1000+
*this, std::move(__array), __type_list<_If<true, _Up, _Tp>...>(), __index_sequence_for<_Tp...>());
10041001
return *this;
10051002
}
10061003

0 commit comments

Comments
 (0)