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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef _LIBCPP___UTILITY_INTEGER_SEQUENCE_H
10 #define _LIBCPP___UTILITY_INTEGER_SEQUENCE_H
11 
12 #include <__config>
13 #include <type_traits>
14 
15 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16 #pragma GCC system_header
17 #endif
18 
19 _LIBCPP_BEGIN_NAMESPACE_STD
20 
21 #if _LIBCPP_STD_VER > 11
22 
23 template<class _Tp, _Tp... _Ip>
24 struct _LIBCPP_TEMPLATE_VIS integer_sequence
25 {
26     typedef _Tp value_type;
27     static_assert( is_integral<_Tp>::value,
28                   "std::integer_sequence can only be instantiated with an integral type" );
29     static
30     _LIBCPP_INLINE_VISIBILITY
31     constexpr
32     size_t
33     size() noexcept { return sizeof...(_Ip); }
34 };
35 
36 template<size_t... _Ip>
37     using index_sequence = integer_sequence<size_t, _Ip...>;
38 
39 #if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
40 
41 template <class _Tp, _Tp _Ep>
42 using __make_integer_sequence _LIBCPP_NODEBUG = __make_integer_seq<integer_sequence, _Tp, _Ep>;
43 
44 #else
45 
46 template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked _LIBCPP_NODEBUG =
47   typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>;
48 
49 template <class _Tp, _Tp _Ep>
50 struct __make_integer_sequence_checked
51 {
52     static_assert(is_integral<_Tp>::value,
53                   "std::make_integer_sequence can only be instantiated with an integral type" );
54     static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length");
55     // Workaround GCC bug by preventing bad installations when 0 <= _Ep
56     // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929
57     typedef _LIBCPP_NODEBUG __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type;
58 };
59 
60 template <class _Tp, _Tp _Ep>
61 using __make_integer_sequence _LIBCPP_NODEBUG = typename __make_integer_sequence_checked<_Tp, _Ep>::type;
62 
63 #endif
64 
65 template<class _Tp, _Tp _Np>
66     using make_integer_sequence = __make_integer_sequence<_Tp, _Np>;
67 
68 template<size_t _Np>
69     using make_index_sequence = make_integer_sequence<size_t, _Np>;
70 
71 template<class... _Tp>
72     using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
73 
74 #endif // _LIBCPP_STD_VER > 11
75 
76 _LIBCPP_END_NAMESPACE_STD
77 
78 #endif // _LIBCPP___UTILITY_INTEGER_SEQUENCE_H
79