Skip to content

Commit c5fcc3a

Browse files
committed
[libc++] Refactor internal index_sequence API to match the public one
1 parent 90f733c commit c5fcc3a

File tree

18 files changed

+139
-208
lines changed

18 files changed

+139
-208
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ set(files
780780
__tuple/make_tuple_types.h
781781
__tuple/sfinae_helpers.h
782782
__tuple/tuple_element.h
783-
__tuple/tuple_indices.h
784783
__tuple/tuple_like.h
785784
__tuple/tuple_like_ext.h
786785
__tuple/tuple_like_no_subrange.h

libcxx/include/__functional/bind.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,14 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& __mu(reference_w
8383

8484
template <class _Ti, class... _Uj, size_t... _Indx>
8585
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<_Ti&, _Uj...>
86-
__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) {
86+
__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __index_sequence<_Indx...>) {
8787
return __ti(std::forward<_Uj>(std::get<_Indx>(__uj))...);
8888
}
8989

9090
template <class _Ti, class... _Uj, __enable_if_t<is_bind_expression<_Ti>::value, int> = 0>
9191
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<_Ti&, _Uj...>
9292
__mu(_Ti& __ti, tuple<_Uj...>& __uj) {
93-
typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
94-
return std::__mu_expand(__ti, __uj, __indices());
93+
return std::__mu_expand(__ti, __uj, __make_index_sequence<sizeof...(_Uj)>());
9594
}
9695

9796
template <bool _IsPh, class _Ti, class _Uj>
@@ -191,7 +190,7 @@ struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> {
191190

192191
template <class _Fp, class _BoundArgs, size_t... _Indx, class _Args>
193192
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bind_return<_Fp, _BoundArgs, _Args>::type
194-
__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, _Args&& __args) {
193+
__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __index_sequence<_Indx...>, _Args&& __args) {
195194
return std::__invoke(__f, std::__mu(std::get<_Indx>(__bound_args), __args)...);
196195
}
197196

@@ -205,8 +204,6 @@ class __bind : public __weak_result_type<__decay_t<_Fp> > {
205204
_Fd __f_;
206205
_Td __bound_args_;
207206

208-
typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
209-
210207
public:
211208
template <
212209
class _Gp,
@@ -219,14 +216,22 @@ class __bind : public __weak_result_type<__decay_t<_Fp> > {
219216
template <class... _Args>
220217
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
221218
operator()(_Args&&... __args) {
222-
return std::__apply_functor(__f_, __bound_args_, __indices(), tuple<_Args&&...>(std::forward<_Args>(__args)...));
219+
return std::__apply_functor(
220+
__f_,
221+
__bound_args_,
222+
__make_index_sequence<sizeof...(_BoundArgs)>(),
223+
tuple<_Args&&...>(std::forward<_Args>(__args)...));
223224
}
224225

225226
template <class... _Args>
226227
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
227228
typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
228229
operator()(_Args&&... __args) const {
229-
return std::__apply_functor(__f_, __bound_args_, __indices(), tuple<_Args&&...>(std::forward<_Args>(__args)...));
230+
return std::__apply_functor(
231+
__f_,
232+
__bound_args_,
233+
__make_index_sequence<sizeof...(_BoundArgs)>(),
234+
tuple<_Args&&...>(std::forward<_Args>(__args)...));
230235
}
231236
};
232237

libcxx/include/__memory_resource/polymorphic_allocator.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ class _LIBCPP_AVAILABILITY_PMR polymorphic_allocator {
135135
piecewise_construct,
136136
__transform_tuple(typename __uses_alloc_ctor< _T1, polymorphic_allocator&, _Args1... >::type(),
137137
std::move(__x),
138-
typename __make_tuple_indices<sizeof...(_Args1)>::type{}),
138+
make_index_sequence<sizeof...(_Args1)>()),
139139
__transform_tuple(typename __uses_alloc_ctor< _T2, polymorphic_allocator&, _Args2... >::type(),
140140
std::move(__y),
141-
typename __make_tuple_indices<sizeof...(_Args2)>::type{}));
141+
make_index_sequence<sizeof...(_Args2)>()));
142142
}
143143

144144
template <class _T1, class _T2>
@@ -194,20 +194,20 @@ class _LIBCPP_AVAILABILITY_PMR polymorphic_allocator {
194194
private:
195195
template <class... _Args, size_t... _Is>
196196
_LIBCPP_HIDE_FROM_ABI tuple<_Args&&...>
197-
__transform_tuple(integral_constant<int, 0>, tuple<_Args...>&& __t, __tuple_indices<_Is...>) {
197+
__transform_tuple(integral_constant<int, 0>, tuple<_Args...>&& __t, index_sequence<_Is...>) {
198198
return std::forward_as_tuple(std::get<_Is>(std::move(__t))...);
199199
}
200200

201201
template <class... _Args, size_t... _Is>
202202
_LIBCPP_HIDE_FROM_ABI tuple<allocator_arg_t const&, polymorphic_allocator&, _Args&&...>
203-
__transform_tuple(integral_constant<int, 1>, tuple<_Args...>&& __t, __tuple_indices<_Is...>) {
203+
__transform_tuple(integral_constant<int, 1>, tuple<_Args...>&& __t, index_sequence<_Is...>) {
204204
using _Tup = tuple<allocator_arg_t const&, polymorphic_allocator&, _Args&&...>;
205205
return _Tup(allocator_arg, *this, std::get<_Is>(std::move(__t))...);
206206
}
207207

208208
template <class... _Args, size_t... _Is>
209209
_LIBCPP_HIDE_FROM_ABI tuple<_Args&&..., polymorphic_allocator&>
210-
__transform_tuple(integral_constant<int, 2>, tuple<_Args...>&& __t, __tuple_indices<_Is...>) {
210+
__transform_tuple(integral_constant<int, 2>, tuple<_Args...>&& __t, index_sequence<_Is...>) {
211211
using _Tup = tuple<_Args&&..., polymorphic_allocator&>;
212212
return _Tup(std::get<_Is>(std::move(__t))..., *this);
213213
}

libcxx/include/__mutex/once_flag.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#include <__functional/invoke.h>
1414
#include <__memory/addressof.h>
1515
#include <__memory/shared_count.h> // __libcpp_acquire_load
16-
#include <__tuple/tuple_indices.h>
1716
#include <__tuple/tuple_size.h>
1817
#include <__utility/forward.h>
18+
#include <__utility/integer_sequence.h>
1919
#include <__utility/move.h>
2020
#include <cstdint>
2121
#ifndef _LIBCPP_CXX03_LANG
@@ -87,15 +87,12 @@ class __call_once_param {
8787
public:
8888
_LIBCPP_HIDE_FROM_ABI explicit __call_once_param(_Fp& __f) : __f_(__f) {}
8989

90-
_LIBCPP_HIDE_FROM_ABI void operator()() {
91-
typedef typename __make_tuple_indices<tuple_size<_Fp>::value, 1>::type _Index;
92-
__execute(_Index());
93-
}
90+
_LIBCPP_HIDE_FROM_ABI void operator()() { __execute(__make_index_sequence<tuple_size<_Fp>::value>()); }
9491

9592
private:
9693
template <size_t... _Indices>
97-
_LIBCPP_HIDE_FROM_ABI void __execute(__tuple_indices<_Indices...>) {
98-
std::__invoke(std::get<0>(std::move(__f_)), std::get<_Indices>(std::move(__f_))...);
94+
_LIBCPP_HIDE_FROM_ABI void __execute(__index_sequence<_Indices...>) {
95+
std::__invoke(std::get<_Indices>(std::move(__f_))...);
9996
}
10097
};
10198

libcxx/include/__thread/thread.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,16 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id) {
155155
# ifndef _LIBCPP_CXX03_LANG
156156

157157
template <class _TSp, class _Fp, class... _Args, size_t... _Indices>
158-
inline _LIBCPP_HIDE_FROM_ABI void __thread_execute(tuple<_TSp, _Fp, _Args...>& __t, __tuple_indices<_Indices...>) {
159-
std::__invoke(std::move(std::get<1>(__t)), std::move(std::get<_Indices>(__t))...);
158+
inline _LIBCPP_HIDE_FROM_ABI void __thread_execute(tuple<_TSp, _Fp, _Args...>& __t, __index_sequence<_Indices...>) {
159+
std::__invoke(std::move(std::get<_Indices + 1>(__t))...);
160160
}
161161

162162
template <class _Fp>
163163
_LIBCPP_HIDE_FROM_ABI void* __thread_proxy(void* __vp) {
164164
// _Fp = tuple< unique_ptr<__thread_struct>, Functor, Args...>
165165
unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp));
166166
__thread_local_data().set_pointer(std::get<0>(*__p.get()).release());
167-
typedef typename __make_tuple_indices<tuple_size<_Fp>::value, 2>::type _Index;
168-
std::__thread_execute(*__p.get(), _Index());
167+
std::__thread_execute(*__p.get(), __make_index_sequence<tuple_size<_Fp>::value - 1>());
169168
return nullptr;
170169
}
171170

libcxx/include/__tuple/make_tuple_types.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
#include <__fwd/array.h>
1515
#include <__fwd/tuple.h>
1616
#include <__tuple/tuple_element.h>
17-
#include <__tuple/tuple_indices.h>
1817
#include <__tuple/tuple_size.h>
1918
#include <__tuple/tuple_types.h>
2019
#include <__type_traits/copy_cvref.h>
2120
#include <__type_traits/remove_cvref.h>
2221
#include <__type_traits/remove_reference.h>
22+
#include <__utility/integer_sequence.h>
2323

2424
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2525
# pragma GCC system_header
@@ -38,38 +38,35 @@ template <class _TupleTypes, class _TupleIndices>
3838
struct __make_tuple_types_flat;
3939

4040
template <template <class...> class _Tuple, class... _Types, size_t... _Idx>
41-
struct __make_tuple_types_flat<_Tuple<_Types...>, __tuple_indices<_Idx...>> {
41+
struct __make_tuple_types_flat<_Tuple<_Types...>, __index_sequence<_Idx...>> {
4242
// Specialization for pair, tuple, and __tuple_types
4343
template <class _Tp>
4444
using __apply_quals _LIBCPP_NODEBUG = __tuple_types<__copy_cvref_t<_Tp, __type_pack_element<_Idx, _Types...>>...>;
4545
};
4646

4747
template <class _Vt, size_t _Np, size_t... _Idx>
48-
struct __make_tuple_types_flat<array<_Vt, _Np>, __tuple_indices<_Idx...>> {
48+
struct __make_tuple_types_flat<array<_Vt, _Np>, __index_sequence<_Idx...>> {
4949
template <size_t>
5050
using __value_type _LIBCPP_NODEBUG = _Vt;
5151
template <class _Tp>
5252
using __apply_quals _LIBCPP_NODEBUG = __tuple_types<__copy_cvref_t<_Tp, __value_type<_Idx>>...>;
5353
};
5454

55-
template <class _Tp,
56-
size_t _Ep = tuple_size<__libcpp_remove_reference_t<_Tp> >::value,
57-
size_t _Sp = 0,
58-
bool _SameSize = (_Ep == tuple_size<__libcpp_remove_reference_t<_Tp> >::value)>
55+
template <class _Tp>
5956
struct __make_tuple_types {
60-
static_assert(_Sp <= _Ep, "__make_tuple_types input error");
6157
using _RawTp _LIBCPP_NODEBUG = __remove_cvref_t<_Tp>;
62-
using _Maker _LIBCPP_NODEBUG = __make_tuple_types_flat<_RawTp, typename __make_tuple_indices<_Ep, _Sp>::type>;
63-
using type _LIBCPP_NODEBUG = typename _Maker::template __apply_quals<_Tp>;
58+
using _Maker _LIBCPP_NODEBUG =
59+
__make_tuple_types_flat<_RawTp, __make_index_sequence<tuple_size<__libcpp_remove_reference_t<_Tp>>::value>>;
60+
using type _LIBCPP_NODEBUG = typename _Maker::template __apply_quals<_Tp>;
6461
};
6562

66-
template <class... _Types, size_t _Ep>
67-
struct __make_tuple_types<tuple<_Types...>, _Ep, 0, true> {
63+
template <class... _Types>
64+
struct __make_tuple_types<tuple<_Types...>> {
6865
using type _LIBCPP_NODEBUG = __tuple_types<_Types...>;
6966
};
7067

71-
template <class... _Types, size_t _Ep>
72-
struct __make_tuple_types<__tuple_types<_Types...>, _Ep, 0, true> {
68+
template <class... _Types>
69+
struct __make_tuple_types<__tuple_types<_Types...>> {
7370
using type _LIBCPP_NODEBUG = __tuple_types<_Types...>;
7471
};
7572

libcxx/include/__tuple/tuple_element.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <__config>
1313
#include <__cstddef/size_t.h>
14-
#include <__tuple/tuple_indices.h>
1514
#include <__tuple/tuple_types.h>
1615

1716
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

libcxx/include/__tuple/tuple_indices.h

Lines changed: 0 additions & 37 deletions
This file was deleted.

libcxx/include/__utility/integer_sequence.h

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,74 +17,60 @@
1717
# pragma GCC system_header
1818
#endif
1919

20+
#ifndef _LIBCPP_CXX03_LANG
21+
2022
_LIBCPP_BEGIN_NAMESPACE_STD
2123

22-
template <size_t...>
23-
struct __tuple_indices;
24+
# if __has_builtin(__make_integer_seq)
25+
template <template <class _Tp, _Tp...> class _BaseType, class _Tp, _Tp _SequenceSize>
26+
using __make_integer_sequence_impl _LIBCPP_NODEBUG = __make_integer_seq<_BaseType, _Tp, _SequenceSize>;
27+
# else
28+
template <template <class _Tp, _Tp...> class _BaseType, class _Tp, _Tp _SequenceSize>
29+
using __make_integer_sequence_impl _LIBCPP_NODEBUG = _BaseType<_Tp, __integer_pack(_SequenceSize)...>;
30+
# endif
2431

25-
template <class _IdxType, _IdxType... _Values>
32+
template <class _Tp, _Tp... _Indices>
2633
struct __integer_sequence {
27-
template <template <class _OIdxType, _OIdxType...> class _ToIndexSeq, class _ToIndexType>
28-
using __convert _LIBCPP_NODEBUG = _ToIndexSeq<_ToIndexType, _Values...>;
29-
30-
template <size_t _Sp>
31-
using __to_tuple_indices _LIBCPP_NODEBUG = __tuple_indices<(_Values + _Sp)...>;
34+
using value_type = _Tp;
35+
static_assert(is_integral<_Tp>::value, "std::integer_sequence can only be instantiated with an integral type");
36+
static _LIBCPP_HIDE_FROM_ABI constexpr size_t size() noexcept { return sizeof...(_Indices); }
3237
};
3338

34-
#if __has_builtin(__make_integer_seq)
35-
template <size_t _Ep, size_t _Sp>
36-
using __make_indices_imp _LIBCPP_NODEBUG =
37-
typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template __to_tuple_indices<_Sp>;
38-
#elif __has_builtin(__integer_pack)
39-
template <size_t _Ep, size_t _Sp>
40-
using __make_indices_imp _LIBCPP_NODEBUG =
41-
typename __integer_sequence<size_t, __integer_pack(_Ep - _Sp)...>::template __to_tuple_indices<_Sp>;
42-
#else
43-
# error "No known way to get an integer pack from the compiler"
44-
#endif
39+
template <size_t... _Indices>
40+
using __index_sequence _LIBCPP_NODEBUG = __integer_sequence<size_t, _Indices...>;
4541

46-
#if _LIBCPP_STD_VER >= 14
42+
template <size_t _SequenceSize>
43+
using __make_index_sequence _LIBCPP_NODEBUG = __make_integer_sequence_impl<__integer_sequence, size_t, _SequenceSize>;
4744

48-
template <class _Tp, _Tp... _Ip>
49-
struct integer_sequence {
50-
typedef _Tp value_type;
51-
static_assert(is_integral<_Tp>::value, "std::integer_sequence can only be instantiated with an integral type");
52-
static _LIBCPP_HIDE_FROM_ABI constexpr size_t size() noexcept { return sizeof...(_Ip); }
53-
};
45+
# if _LIBCPP_STD_VER >= 14
46+
47+
template <class _Tp, _Tp... _Indices>
48+
struct integer_sequence : __integer_sequence<_Tp, _Indices...> {};
5449

5550
template <size_t... _Ip>
5651
using index_sequence = integer_sequence<size_t, _Ip...>;
5752

58-
# if __has_builtin(__make_integer_seq)
59-
6053
template <class _Tp, _Tp _Ep>
61-
using make_integer_sequence _LIBCPP_NODEBUG = __make_integer_seq<integer_sequence, _Tp, _Ep>;
62-
63-
# elif __has_builtin(__integer_pack)
64-
65-
template <class _Tp, _Tp _SequenceSize>
66-
using make_integer_sequence _LIBCPP_NODEBUG = integer_sequence<_Tp, __integer_pack(_SequenceSize)...>;
67-
68-
# else
69-
# error "No known way to get an integer pack from the compiler"
70-
# endif
54+
using make_integer_sequence _LIBCPP_NODEBUG = __make_integer_sequence_impl<integer_sequence, _Tp, _Ep>;
7155

7256
template <size_t _Np>
7357
using make_index_sequence = make_integer_sequence<size_t, _Np>;
7458

7559
template <class... _Tp>
7660
using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
7761

78-
# if _LIBCPP_STD_VER >= 20
62+
# if _LIBCPP_STD_VER >= 20
7963
// Executes __func for every element in an index_sequence.
8064
template <size_t... _Index, class _Function>
8165
_LIBCPP_HIDE_FROM_ABI constexpr void __for_each_index_sequence(index_sequence<_Index...>, _Function __func) {
8266
(__func.template operator()<_Index>(), ...);
8367
}
84-
# endif // _LIBCPP_STD_VER >= 20
68+
# endif // _LIBCPP_STD_VER >= 20
8569

86-
#endif // _LIBCPP_STD_VER >= 14
70+
# endif // _LIBCPP_STD_VER >= 14
8771

8872
_LIBCPP_END_NAMESPACE_STD
8973

74+
#endif // _LIBCPP_CXX03_LANG
75+
9076
#endif // _LIBCPP___UTILITY_INTEGER_SEQUENCE_H

0 commit comments

Comments
 (0)