40 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/__support/CPP/utility.h"10#include "test/UnitTest/Test.h"11 12using namespace LIBC_NAMESPACE::cpp;13 14TEST(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 26template <typename T, T... Ts>27bool checkArray([[maybe_unused]] integer_sequence<T, Ts...> seq) {28 T arr[sizeof...(Ts)]{Ts...};29 30 for (T i = 0; i < static_cast<T>(sizeof...(Ts)); i++)31 if (arr[i] != i)32 return false;33 34 return true;35}36 37TEST(LlvmLibcIntegerSequencetTest, Many) {38 EXPECT_TRUE(checkArray(make_integer_sequence<int, 100>{}));39}40