|
17 | 17 | # pragma GCC system_header |
18 | 18 | #endif |
19 | 19 |
|
| 20 | +#ifndef _LIBCPP_CXX03_LANG |
| 21 | + |
20 | 22 | _LIBCPP_BEGIN_NAMESPACE_STD |
21 | 23 |
|
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 |
24 | 31 |
|
25 | | -template <class _IdxType, _IdxType... _Values> |
| 32 | +template <class _Tp, _Tp... _Indices> |
26 | 33 | 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); } |
32 | 37 | }; |
33 | 38 |
|
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...>; |
45 | 41 |
|
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>; |
47 | 44 |
|
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...> {}; |
54 | 49 |
|
55 | 50 | template <size_t... _Ip> |
56 | 51 | using index_sequence = integer_sequence<size_t, _Ip...>; |
57 | 52 |
|
58 | | -# if __has_builtin(__make_integer_seq) |
59 | | - |
60 | 53 | 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>; |
71 | 55 |
|
72 | 56 | template <size_t _Np> |
73 | 57 | using make_index_sequence = make_integer_sequence<size_t, _Np>; |
74 | 58 |
|
75 | 59 | template <class... _Tp> |
76 | 60 | using index_sequence_for = make_index_sequence<sizeof...(_Tp)>; |
77 | 61 |
|
78 | | -# if _LIBCPP_STD_VER >= 20 |
| 62 | +# if _LIBCPP_STD_VER >= 20 |
79 | 63 | // Executes __func for every element in an index_sequence. |
80 | 64 | template <size_t... _Index, class _Function> |
81 | 65 | _LIBCPP_HIDE_FROM_ABI constexpr void __for_each_index_sequence(index_sequence<_Index...>, _Function __func) { |
82 | 66 | (__func.template operator()<_Index>(), ...); |
83 | 67 | } |
84 | | -# endif // _LIBCPP_STD_VER >= 20 |
| 68 | +# endif // _LIBCPP_STD_VER >= 20 |
85 | 69 |
|
86 | | -#endif // _LIBCPP_STD_VER >= 14 |
| 70 | +# endif // _LIBCPP_STD_VER >= 14 |
87 | 71 |
|
88 | 72 | _LIBCPP_END_NAMESPACE_STD |
89 | 73 |
|
| 74 | +#endif // _LIBCPP_CXX03_LANG |
| 75 | + |
90 | 76 | #endif // _LIBCPP___UTILITY_INTEGER_SEQUENCE_H |
0 commit comments