File indexing completed on 2026-05-03 08:14:06
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___UTILITY_INTEGER_SEQUENCE_H
0010 #define _LIBCPP___UTILITY_INTEGER_SEQUENCE_H
0011
0012 #include <__config>
0013 #include <__cstddef/size_t.h>
0014 #include <__type_traits/is_integral.h>
0015
0016 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0017 # pragma GCC system_header
0018 #endif
0019
0020 _LIBCPP_BEGIN_NAMESPACE_STD
0021
0022 template <size_t...>
0023 struct __tuple_indices;
0024
0025 template <class _IdxType, _IdxType... _Values>
0026 struct __integer_sequence {
0027 template <template <class _OIdxType, _OIdxType...> class _ToIndexSeq, class _ToIndexType>
0028 using __convert _LIBCPP_NODEBUG = _ToIndexSeq<_ToIndexType, _Values...>;
0029
0030 template <size_t _Sp>
0031 using __to_tuple_indices _LIBCPP_NODEBUG = __tuple_indices<(_Values + _Sp)...>;
0032 };
0033
0034 #if __has_builtin(__make_integer_seq)
0035 template <size_t _Ep, size_t _Sp>
0036 using __make_indices_imp _LIBCPP_NODEBUG =
0037 typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template __to_tuple_indices<_Sp>;
0038 #elif __has_builtin(__integer_pack)
0039 template <size_t _Ep, size_t _Sp>
0040 using __make_indices_imp _LIBCPP_NODEBUG =
0041 typename __integer_sequence<size_t, __integer_pack(_Ep - _Sp)...>::template __to_tuple_indices<_Sp>;
0042 #else
0043 # error "No known way to get an integer pack from the compiler"
0044 #endif
0045
0046 #if _LIBCPP_STD_VER >= 14
0047
0048 template <class _Tp, _Tp... _Ip>
0049 struct _LIBCPP_TEMPLATE_VIS integer_sequence {
0050 typedef _Tp value_type;
0051 static_assert(is_integral<_Tp>::value, "std::integer_sequence can only be instantiated with an integral type");
0052 static _LIBCPP_HIDE_FROM_ABI constexpr size_t size() noexcept { return sizeof...(_Ip); }
0053 };
0054
0055 template <size_t... _Ip>
0056 using index_sequence = integer_sequence<size_t, _Ip...>;
0057
0058 # if __has_builtin(__make_integer_seq)
0059
0060 template <class _Tp, _Tp _Ep>
0061 using make_integer_sequence _LIBCPP_NODEBUG = __make_integer_seq<integer_sequence, _Tp, _Ep>;
0062
0063 # elif __has_builtin(__integer_pack)
0064
0065 template <class _Tp, _Tp _SequenceSize>
0066 using make_integer_sequence _LIBCPP_NODEBUG = integer_sequence<_Tp, __integer_pack(_SequenceSize)...>;
0067
0068 # else
0069 # error "No known way to get an integer pack from the compiler"
0070 # endif
0071
0072 template <size_t _Np>
0073 using make_index_sequence = make_integer_sequence<size_t, _Np>;
0074
0075 template <class... _Tp>
0076 using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
0077
0078 # if _LIBCPP_STD_VER >= 20
0079
0080 template <size_t... _Index, class _Function>
0081 _LIBCPP_HIDE_FROM_ABI constexpr void __for_each_index_sequence(index_sequence<_Index...>, _Function __func) {
0082 (__func.template operator()<_Index>(), ...);
0083 }
0084 # endif
0085
0086 #endif
0087
0088 _LIBCPP_END_NAMESPACE_STD
0089
0090 #endif