32 SECTION(
"non-empty") {
33 vector<int> v = {1, 2, 3, 4, 5};
55 SECTION(
"non-empty") {
56 std::list<int> l = {1, 2, 3, 4, 5};
92 SECTION(
"non-empty") {
93 vector<int> v = {1, 2, 3, 4, 5};
115 SECTION(
"non-empty") {
116 std::list<int> l = {1, 2, 3, 4, 5};
133 vector<int> in = {1, 2, 3, 4};
134 for (
const auto& e :
reverse(in)) out.push_back(e);
135 CHECK(out == vector<int>{4, 3, 2, 1});
138 for (
const auto& e :
reverse(getVector(3))) out.push_back(e);
139 CHECK(out == vector<int>{2, 1, 0});
141 SECTION(
"2 x reverse") {
142 for (
const auto& e :
reverse(
reverse(getVector(4)))) out.push_back(e);
143 CHECK(out == vector<int>{0, 1, 2, 3});
149 auto square = [](
auto& x) {
return x * x; };
151 auto plus_i = [&](
auto& x) {
return int(x + i); };
154 vector<int> v = {1, 2, 3, 4};
212 SECTION(
"std::map") {
213 std::map<int, int> m = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
214 check(
keys (m), vector<int>{1, 3, 5, 7});
215 check(
values(m), vector<int>{2, 4, 6, 8});
217 SECTION(
"std::vector<std::pair>") {
218 vector<std::pair<int, int>> v = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
219 check(
keys (v), vector<int>{1, 3, 5, 7});
220 check(
values(v), vector<int>{2, 4, 6, 8});
222 SECTION(
"hash_map") {
224 {
"foo", 1}, {
"bar", 2}, {
"qux", 3},
225 {
"baz", 4}, {
"a", 5}, {
"z", 6}
227 check_unordered(
keys(m), vector<std::string>{
228 "foo",
"bar",
"qux",
"baz",
"a",
"z"});
229 check_unordered(
values(m), vector<int>{1, 2, 3, 4, 5, 6});
231 SECTION(
"std::vector<std::tuple>") {
232 vector<std::tuple<int, char, double, std::string>> v = {
233 std::tuple(1, 2, 1.2,
"foo"),
234 std::tuple(3, 4, 3.4,
"bar"),
235 std::tuple(5, 6, 5.6,
"qux")
237 check(
keys (v), vector<int>{1, 3, 5});
238 check(
values(v), vector<char>{2, 4, 6});
250 vector v = {1, 2, 3, 4, 5, 6, 7, 8, 9};
252 SECTION(
"removed front") {
256 SECTION(
"removed back") {
260 SECTION(
"keep front and back") {
262 vector{1, 3, 5, 7, 9});
264 SECTION(
"remove front and back") {
265 check(
view::filter(v, [](
int i) {
return (i & 1) == 0; }),
269 SECTION(
"projection") {
270 vector<F> f = {1, 2, 3, 4, 5};
272 auto it =
view.begin();
273 auto et =
view.end();
289 vector v = {1, 2, 3, 4};
298 SECTION(
"split_view") {
299 std::string_view str =
"abc def\t \tghi jkl mno pqr";
300 auto v =
view::take(StringOp::split_view<StringOp::EmptyParts::REMOVE>(str,
" \t"), 3);
342 std::vector
v4 = {1, 2, 3, 4};
343 std::array a3 = {
'a',
'b',
'c'};
344 std::list
l4 = {1.2, 2.3, 3.4, 4.5};
346 test_zip(
v4, a3, std::vector<std::tuple<int, char>>{{1,
'a'}, {2,
'b'}, {3,
'c'}});
347 test_zip(a3,
v4, std::vector<std::tuple<char, int>>{{
'a', 1}, {
'b', 2}, {
'c', 3}});
349 test_zip(
v4,
l4, std::vector<std::tuple<int, double>>{{1, 1.2}, {2, 2.3}, {3, 3.4}, {4, 4.5}});
350 test_zip(
l4,
v4, std::vector<std::tuple<double, int>>{{1.2, 1}, {2.3, 2}, {3.4, 3}, {4.5, 4}});
352 test_zip(a3,
l4, std::vector<std::tuple<char, double>>{{
'a', 1.2}, {
'b', 2.3}, {
'c', 3.4}});
353 test_zip(
l4, a3, std::vector<std::tuple<double, char>>{{1.2,
'a'}, {2.3,
'b'}, {3.4,
'c'}});
355 test_zip(
v4, a3,
l4, std::vector<std::tuple<int, char, double>>{{1,
'a', 1.2}, {2,
'b', 2.3}, {3,
'c', 3.4}});
357 for (
auto [x, y] :
zip(
v4, a3)) {
361 CHECK(
v4 == std::vector{0, 0, 0, 4});
362 CHECK(a3 == std::array{
'b',
'c',
'd'});
387 std::vector v = {1, 2, 3};
388 std::array a = {
'a',
'b',
'c'};
389 std::list l = {1.2, 2.3, 3.4};
391 test_zip_equal(v, a, std::vector<std::tuple<int, char>>{{1,
'a'}, {2,
'b'}, {3,
'c'}});
392 test_zip_equal(v, l, std::vector<std::tuple<int, double>>{{1, 1.2}, {2, 2.3}, {3, 3.4}});
393 test_zip_equal(a, l, std::vector<std::tuple<char, double>>{{
'a', 1.2}, {
'b', 2.3}, {
'c', 3.4}});
395 test_zip_equal(v, a, l, std::vector<std::tuple<int, char, double>>{{1,
'a', 1.2}, {2,
'b', 2.3}, {3,
'c', 3.4}});
397 for (
auto [x, y, z] :
zip_equal(v, l, a)) {
402 CHECK(v == std::vector{0, 0, 0});
403 CHECK(a == std::array{
'c',
'd',
'e'});
404 CHECK(l == std::list{2.4, 4.6, 6.8});
imat4 l4(ivec4(1, 2, 3, 4), ivec4(3, 4, 5, 6), ivec4(5, 6, 7, 0), ivec4(7, 8, 9, 0))