77 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___UTILITY_INTEGER_SEQUENCE_H10#define _LIBCPP___UTILITY_INTEGER_SEQUENCE_H11 12#include <__config>13#include <__cstddef/size_t.h>14#include <__type_traits/is_integral.h>15 16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)17# pragma GCC system_header18#endif19 20#ifndef _LIBCPP_CXX03_LANG21 22_LIBCPP_BEGIN_NAMESPACE_STD23 24# if __has_builtin(__make_integer_seq)25template <template <class _Tp, _Tp...> class _BaseType, class _Tp, _Tp _SequenceSize>26using __make_integer_sequence_impl _LIBCPP_NODEBUG = __make_integer_seq<_BaseType, _Tp, _SequenceSize>;27# else28template <template <class _Tp, _Tp...> class _BaseType, class _Tp, _Tp _SequenceSize>29using __make_integer_sequence_impl _LIBCPP_NODEBUG = _BaseType<_Tp, __integer_pack(_SequenceSize)...>;30# endif31 32template <class _Tp, _Tp... _Indices>33struct __integer_sequence {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); }37};38 39template <size_t... _Indices>40using __index_sequence _LIBCPP_NODEBUG = __integer_sequence<size_t, _Indices...>;41 42template <size_t _SequenceSize>43using __make_index_sequence _LIBCPP_NODEBUG = __make_integer_sequence_impl<__integer_sequence, size_t, _SequenceSize>;44 45# if _LIBCPP_STD_VER >= 1446 47template <class _Tp, _Tp... _Indices>48struct integer_sequence : __integer_sequence<_Tp, _Indices...> {};49 50template <size_t... _Ip>51using index_sequence = integer_sequence<size_t, _Ip...>;52 53template <class _Tp, _Tp _Ep>54using make_integer_sequence _LIBCPP_NODEBUG = __make_integer_sequence_impl<integer_sequence, _Tp, _Ep>;55 56template <size_t _Np>57using make_index_sequence = make_integer_sequence<size_t, _Np>;58 59template <class... _Tp>60using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;61 62# if _LIBCPP_STD_VER >= 2063// Executes __func for every element in an index_sequence.64template <size_t... _Index, class _Function>65_LIBCPP_HIDE_FROM_ABI constexpr void __for_each_index_sequence(index_sequence<_Index...>, _Function __func) {66 (__func.template operator()<_Index>(), ...);67}68# endif // _LIBCPP_STD_VER >= 2069 70# endif // _LIBCPP_STD_VER >= 1471 72_LIBCPP_END_NAMESPACE_STD73 74#endif // _LIBCPP_CXX03_LANG75 76#endif // _LIBCPP___UTILITY_INTEGER_SEQUENCE_H77