summaryrefslogtreecommitdiff
path: root/libc/test/src/__support/CPP/integer_sequence_test.cpp
blob: 590fb4ede4cda6766e54c2a2149fef2c66eba884 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//===-- Unittests for IntegerSequence -------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/__support/CPP/utility.h"
#include "test/UnitTest/Test.h"

using namespace LIBC_NAMESPACE::cpp;

TEST(LlvmLibcIntegerSequencetTest, Basic) {
  EXPECT_TRUE(
      (is_same_v<integer_sequence<int>, make_integer_sequence<int, 0>>));
  using ISeq = integer_sequence<int, 0, 1, 2, 3>;
  EXPECT_TRUE((is_same_v<ISeq, make_integer_sequence<int, 4>>));
  using LSeq = integer_sequence<long, 0, 1, 2, 3>;
  EXPECT_TRUE((is_same_v<LSeq, make_integer_sequence<long, 4>>));
  using ULLSeq = integer_sequence<unsigned long long, 0ull, 1ull, 2ull, 3ull>;
  EXPECT_TRUE(
      (is_same_v<ULLSeq, make_integer_sequence<unsigned long long, 4>>));
}

template <typename T, T... Ts>
bool checkArray([[maybe_unused]] integer_sequence<T, Ts...> seq) {
  T arr[sizeof...(Ts)]{Ts...};

  for (T i = 0; i < static_cast<T>(sizeof...(Ts)); i++)
    if (arr[i] != i)
      return false;

  return true;
}

TEST(LlvmLibcIntegerSequencetTest, Many) {
  EXPECT_TRUE(checkArray(make_integer_sequence<int, 100>{}));
}