xref: /aosp_15_r20/external/llvm-libc/src/__support/CPP/utility/integer_sequence.h (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===-- integer_sequence utility --------------------------------*- C++ -*-===//
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 #ifndef LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_INTEGER_SEQUENCE_H
9 #define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_INTEGER_SEQUENCE_H
10 
11 #include "src/__support/CPP/type_traits/is_integral.h"
12 #include "src/__support/macros/config.h"
13 
14 namespace LIBC_NAMESPACE_DECL {
15 namespace cpp {
16 
17 // integer_sequence
18 template <typename T, T... Ints> struct integer_sequence {
19   static_assert(cpp::is_integral_v<T>);
20   template <T Next> using append = integer_sequence<T, Ints..., Next>;
21 };
22 
23 namespace detail {
24 template <typename T, int N> struct make_integer_sequence {
25   using type =
26       typename make_integer_sequence<T, N - 1>::type::template append<N>;
27 };
28 template <typename T> struct make_integer_sequence<T, -1> {
29   using type = integer_sequence<T>;
30 };
31 } // namespace detail
32 
33 template <typename T, int N>
34 using make_integer_sequence =
35     typename detail::make_integer_sequence<T, N - 1>::type;
36 
37 } // namespace cpp
38 } // namespace LIBC_NAMESPACE_DECL
39 
40 #endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_INTEGER_SEQUENCE_H
41