1 | //===-- Unittests for IntegerSequence -------------------------------------===// |
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 | #include "src/__support/CPP/utility.h" |
10 | #include "test/UnitTest/Test.h" |
11 | |
12 | using namespace LIBC_NAMESPACE::cpp; |
13 | |
14 | TEST(LlvmLibcIntegerSequencetTest, Basic) { |
15 | EXPECT_TRUE( |
16 | (is_same_v<integer_sequence<int>, make_integer_sequence<int, 0>>)); |
17 | using ISeq = integer_sequence<int, 0, 1, 2, 3>; |
18 | EXPECT_TRUE((is_same_v<ISeq, make_integer_sequence<int, 4>>)); |
19 | using LSeq = integer_sequence<long, 0, 1, 2, 3>; |
20 | EXPECT_TRUE((is_same_v<LSeq, make_integer_sequence<long, 4>>)); |
21 | using ULLSeq = integer_sequence<unsigned long long, 0ull, 1ull, 2ull, 3ull>; |
22 | EXPECT_TRUE( |
23 | (is_same_v<ULLSeq, make_integer_sequence<unsigned long long, 4>>)); |
24 | } |
25 | |
26 | template <typename T, T... Ts> bool checkArray(integer_sequence<T, Ts...> seq) { |
27 | T arr[sizeof...(Ts)]{Ts...}; |
28 | |
29 | for (T i = 0; i < static_cast<T>(sizeof...(Ts)); i++) |
30 | if (arr[i] != i) |
31 | return false; |
32 | |
33 | return true; |
34 | } |
35 | |
36 | TEST(LlvmLibcIntegerSequencetTest, Many) { |
37 | EXPECT_TRUE(checkArray(make_integer_sequence<int, 100>{})); |
38 | } |
39 | |