Skip to content

Commit f79867a

Browse files
committed
test copied from std
1 parent 8a61095 commit f79867a

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
#include <ranges>
12+
#include <cassert>
13+
#include <vector>
14+
#include <string>
15+
16+
constexpr bool test() {
17+
struct ConstexprStringStream {
18+
std::string str;
19+
20+
constexpr ConstexprStringStream& operator<<(int x) {
21+
return *this << char(x + 48);
22+
}
23+
constexpr ConstexprStringStream& operator<<(char c) {
24+
str += c;
25+
return *this;
26+
}
27+
};
28+
29+
const std::vector<int> v{0, 1, 2};
30+
ConstexprStringStream out;
31+
// fixme: replace by views::cartesian_product
32+
for (auto&& [a, b, c] : std::ranges::cartesian_product_view(v, v, v)) {
33+
out << a << ' ' << b << ' ' << c << '\n';
34+
}
35+
36+
const std::string_view expected =
37+
"0 0 0\n"
38+
"0 0 1\n"
39+
"0 0 2\n"
40+
"0 1 0\n"
41+
"0 1 1\n"
42+
"0 1 2\n"
43+
"0 2 0\n"
44+
"0 2 1\n"
45+
"0 2 2\n"
46+
"1 0 0\n"
47+
"1 0 1\n"
48+
"1 0 2\n"
49+
"1 1 0\n"
50+
"1 1 1\n"
51+
"1 1 2\n"
52+
"1 2 0\n"
53+
"1 2 1\n"
54+
"1 2 2\n"
55+
"2 0 0\n"
56+
"2 0 1\n"
57+
"2 0 2\n"
58+
"2 1 0\n"
59+
"2 1 1\n"
60+
"2 1 2\n"
61+
"2 2 0\n"
62+
"2 2 1\n"
63+
"2 2 2\n";
64+
assert(out.str == expected);
65+
66+
return true;
67+
}
68+
69+
int main() {
70+
test();
71+
static_assert(test());
72+
}

0 commit comments

Comments
 (0)