Path: blob/main/contrib/llvm-project/libcxx/include/__utility/integer_sequence.h
35236 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___UTILITY_INTEGER_SEQUENCE_H9#define _LIBCPP___UTILITY_INTEGER_SEQUENCE_H1011#include <__config>12#include <__type_traits/is_integral.h>13#include <cstddef>1415#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)16# pragma GCC system_header17#endif1819_LIBCPP_BEGIN_NAMESPACE_STD2021template <size_t...>22struct __tuple_indices;2324template <class _IdxType, _IdxType... _Values>25struct __integer_sequence {26template <template <class _OIdxType, _OIdxType...> class _ToIndexSeq, class _ToIndexType>27using __convert = _ToIndexSeq<_ToIndexType, _Values...>;2829template <size_t _Sp>30using __to_tuple_indices = __tuple_indices<(_Values + _Sp)...>;31};3233#if __has_builtin(__make_integer_seq)34template <size_t _Ep, size_t _Sp>35using __make_indices_imp =36typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template __to_tuple_indices<_Sp>;37#elif __has_builtin(__integer_pack)38template <size_t _Ep, size_t _Sp>39using __make_indices_imp =40typename __integer_sequence<size_t, __integer_pack(_Ep - _Sp)...>::template __to_tuple_indices<_Sp>;41#else42# error "No known way to get an integer pack from the compiler"43#endif4445#if _LIBCPP_STD_VER >= 144647template <class _Tp, _Tp... _Ip>48struct _LIBCPP_TEMPLATE_VIS integer_sequence {49typedef _Tp value_type;50static_assert(is_integral<_Tp>::value, "std::integer_sequence can only be instantiated with an integral type");51static _LIBCPP_HIDE_FROM_ABI constexpr size_t size() noexcept { return sizeof...(_Ip); }52};5354template <size_t... _Ip>55using index_sequence = integer_sequence<size_t, _Ip...>;5657# if __has_builtin(__make_integer_seq)5859template <class _Tp, _Tp _Ep>60using make_integer_sequence _LIBCPP_NODEBUG = __make_integer_seq<integer_sequence, _Tp, _Ep>;6162# elif __has_builtin(__integer_pack)6364template <class _Tp, _Tp _SequenceSize>65using make_integer_sequence _LIBCPP_NODEBUG = integer_sequence<_Tp, __integer_pack(_SequenceSize)...>;6667# else68# error "No known way to get an integer pack from the compiler"69# endif7071template <size_t _Np>72using make_index_sequence = make_integer_sequence<size_t, _Np>;7374template <class... _Tp>75using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;7677# if _LIBCPP_STD_VER >= 2078// Executes __func for every element in an index_sequence.79template <size_t... _Index, class _Function>80_LIBCPP_HIDE_FROM_ABI constexpr void __for_each_index_sequence(index_sequence<_Index...>, _Function __func) {81(__func.template operator()<_Index>(), ...);82}83# endif // _LIBCPP_STD_VER >= 208485#endif // _LIBCPP_STD_VER >= 148687_LIBCPP_END_NAMESPACE_STD8889#endif // _LIBCPP___UTILITY_INTEGER_SEQUENCE_H909192