Skip to content

Commit 088d166

Browse files
committed
test: view::end()
1 parent c87e1ee commit 088d166

File tree

1 file changed

+138
-0
lines changed
  • libcxx/test/std/ranges/range.adaptors/range.cartesian.product.view

1 file changed

+138
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
//===----------------------------------------------------------------------===//
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+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
11+
// constexpr iterator<false> end() requires ((!simple-view <First> || ... || !simple-view <Vs>) && cartesian-product-is-common< First, Vs...>);
12+
// constexpr iterator<true > end() const requires cartesian-product-is-common<const First, const Vs...> ;
13+
14+
#include "assert_macros.h"
15+
16+
#include <array>
17+
#include <cassert>
18+
#include <ranges>
19+
20+
constexpr bool test() {
21+
{ // non-empty range
22+
constexpr size_t N = 7;
23+
std::array<int, N> a;
24+
std::ranges::cartesian_product_view c{a};
25+
assert(c.end() == c.begin() + N);
26+
}
27+
28+
{ // (non-empty range)^2
29+
constexpr size_t N0 = 7;
30+
std::array<int, N0> a0;
31+
constexpr size_t N1 = 42;
32+
std::array<int, N1> a1;
33+
std::ranges::cartesian_product_view c{a0, a1};
34+
assert(c.end() == c.begin() + N0 * N1);
35+
}
36+
37+
{ // (non-empty range)^3
38+
constexpr size_t N0 = 5, N1 = 42, N2 = 7;
39+
std::array<int, N0> a0;
40+
std::array<int, N1> a1;
41+
std::array<int, N2> a2;
42+
std::ranges::cartesian_product_view c{a0, a1, a2};
43+
assert(c.end() == c.begin() + N0*N1*N2);
44+
}
45+
46+
{ // empty range
47+
std::ranges::empty_view<int> e;
48+
std::ranges::cartesian_product_view c{e};
49+
assert(c.end() == c.begin());
50+
}
51+
52+
{ // (empty range)^2
53+
std::ranges::empty_view<int> e;
54+
std::ranges::cartesian_product_view c{e, e};
55+
assert(c.end() == c.begin());
56+
}
57+
58+
{ // empty range X common range
59+
std::ranges::empty_view<int> e;
60+
constexpr size_t N = 7;
61+
std::array<int, N> a;
62+
std::ranges::cartesian_product_view c{e, a};
63+
assert(c.end() == c.begin());
64+
}
65+
66+
{ // common range X empty range
67+
std::ranges::empty_view<int> e;
68+
constexpr size_t N = 7;
69+
std::array<int, N> a;
70+
std::ranges::cartesian_product_view c{e, a};
71+
assert(c.end() == c.begin());
72+
}
73+
74+
{ // (empty range)^3
75+
std::ranges::empty_view<int> e;
76+
std::ranges::cartesian_product_view c{e, e, e};
77+
assert(c.end() == c.begin());
78+
}
79+
80+
{ // empty range X empty range X common range
81+
std::ranges::empty_view<int> e;
82+
constexpr size_t N = 7;
83+
std::array<int, N> a;
84+
std::ranges::cartesian_product_view c{e, e, a};
85+
assert(c.end() == c.begin());
86+
}
87+
88+
{ // empty range X common range X empty range
89+
std::ranges::empty_view<int> e;
90+
constexpr size_t N = 7;
91+
std::array<int, N> a;
92+
std::ranges::cartesian_product_view c{e, a, e};
93+
assert(c.end() == c.begin());
94+
}
95+
96+
{ // common range X empty range X empty range
97+
std::ranges::empty_view<int> e;
98+
constexpr size_t N = 7;
99+
std::array<int, N> a;
100+
std::ranges::cartesian_product_view c{a, e, e};
101+
assert(c.end() == c.begin());
102+
}
103+
104+
{ // empty range X common range X common range
105+
std::ranges::empty_view<int> e;
106+
constexpr size_t N0 = 7, N1 = 42;
107+
std::array<int, N0> a0;
108+
std::array<int, N1> a1;
109+
std::ranges::cartesian_product_view c{e, a0, a1};
110+
assert(c.end() == c.begin());
111+
}
112+
113+
{ // common range X empty range X common range
114+
std::ranges::empty_view<int> e;
115+
constexpr size_t N0 = 7, N1 = 42;
116+
std::array<int, N0> a0;
117+
std::array<int, N1> a1;
118+
std::ranges::cartesian_product_view c{a0, e, a1};
119+
assert(c.end() == c.begin());
120+
}
121+
122+
{ // common range X common range X empty range
123+
std::ranges::empty_view<int> e;
124+
constexpr size_t N0 = 7, N1 = 42;
125+
std::array<int, N0> a0;
126+
std::array<int, N1> a1;
127+
std::ranges::cartesian_product_view c{a0, a1, e};
128+
assert(c.end() == c.begin());
129+
}
130+
131+
return true;
132+
}
133+
134+
int main(int, char**) {
135+
test();
136+
static_assert(test());
137+
return 0;
138+
}

0 commit comments

Comments
 (0)