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