forked from intel/cpp-std-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.cpp
More file actions
79 lines (64 loc) · 2.65 KB
/
array.cpp
File metadata and controls
79 lines (64 loc) · 2.65 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdx/array.hpp>
#include <catch2/catch_test_macros.hpp>
#include <array>
TEST_CASE("make_array (variadic arguments)", "[array]") {
auto arr = stdx::make_array(1, 2, 3, 4, 5);
STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 5>>);
CHECK(arr == std::array{1, 2, 3, 4, 5});
}
TEST_CASE("make_array (zero case)", "[array]") {
auto arr = stdx::make_array<float>();
STATIC_CHECK(std::is_same_v<decltype(arr), std::array<float, 0>>);
}
TEST_CASE("make_array (zero case default)", "[array]") {
auto arr = stdx::make_array();
STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 0>>);
}
namespace {
template <auto I> using V = std::integral_constant<decltype(I), I + 1>;
}
TEST_CASE("make_array by sequence (template with ::value)", "[array]") {
auto arr = stdx::make_array<V>(std::make_integer_sequence<int, 5>{});
STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 5>>);
CHECK(arr == std::array{1, 2, 3, 4, 5});
}
TEST_CASE("make_array by sequence - zero case (template with ::value)",
"[array]") {
auto arr = stdx::make_array<V>(std::make_integer_sequence<int, 0>{});
STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 0>>);
}
TEST_CASE("make_array by extent (template with ::value)", "[array]") {
auto arr = stdx::make_array<V, 5>();
STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 5>>);
CHECK(arr == std::array{1, 2, 3, 4, 5});
}
TEST_CASE("make_array by extent - zero case (template with ::value)",
"[array]") {
auto arr = stdx::make_array<V, 0>();
STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 0>>);
}
namespace {
struct {
template <auto I> auto operator()() { return I + 1; }
} f;
} // namespace
TEST_CASE("make_array by sequence (factory function template)", "[array]") {
auto arr = stdx::make_array(std::make_integer_sequence<int, 5>{}, f);
STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 5>>);
CHECK(arr == std::array{1, 2, 3, 4, 5});
}
TEST_CASE("make_array by sequence - zero case (factory function template)",
"[array]") {
auto arr = stdx::make_array(std::make_integer_sequence<int, 0>{}, f);
STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 0>>);
}
TEST_CASE("make_array by extent (factory function template)", "[array]") {
auto arr = stdx::make_array<5>(f);
STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 5>>);
CHECK(arr == std::array{1, 2, 3, 4, 5});
}
TEST_CASE("make_array by extent - zero case (factory function template)",
"[array]") {
auto arr = stdx::make_array<0>(f);
STATIC_CHECK(std::is_same_v<decltype(arr), std::array<int, 0>>);
}