match.pd: Fix indefinite recursion during exp-log transformations [PR118490]
[gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / find_last / 1.cc
blob8a40bb1a6b36d4b3220c8f227208d7df4c93b6dc
1 // { dg-do run { target c++23 } }
3 #include <algorithm>
4 #include <testsuite_hooks.h>
5 #include <testsuite_iterators.h>
7 #if __cpp_lib_ranges_find_last != 202207L
8 # error "Feature-test macro __cpp_lib_ranges_find_last has wrong value in <algorithm>"
9 #endif
11 namespace ranges = std::ranges;
13 constexpr bool
14 test01()
16 int x[] = {1, 2, 1, 2, 1, 2, 1, 2};
18 auto sr0 = ranges::find_last(x, 0);
19 VERIFY( ranges::empty(sr0) );
20 VERIFY( sr0.begin() == ranges::end(x) );
22 auto sr1 = ranges::find_last(x, 1);
23 VERIFY( ranges::equal(sr1, (int[]){1, 2}) );
24 VERIFY( sr1.begin() == &x[6] );
26 auto sr2 = ranges::find_last(x, 2);
27 VERIFY( ranges::equal(sr2, (int[]){2}) );
28 VERIFY( sr2.begin() == &x[7] );
30 auto plus3 = [](int n) { return n+3; };
32 auto sr3 = ranges::find_last(x, 3, plus3);
33 VERIFY( ranges::empty(sr3) );
34 VERIFY( sr3.begin() == ranges::end(x) );
36 auto sr4 = ranges::find_last(x, 4, plus3);
37 VERIFY( ranges::equal(sr4, (int[]){1, 2}) );
38 VERIFY( sr4.begin() == &x[6] );
40 auto sr5 = ranges::find_last(x, 5, plus3);
41 VERIFY( ranges::equal(sr5, (int[]){2}) );
42 VERIFY( sr5.begin() == &x[7] );
44 return true;
47 void
48 test02()
50 int x[] = {1, 2, 3, 1, 2, 3, 1, 2, 3};
51 __gnu_test::test_forward_range<int> rx(x);
53 auto sr0 = ranges::find_last(rx, 0);
54 VERIFY( ranges::empty(sr0) );
55 VERIFY( sr0.begin() == ranges::end(rx) );
57 auto sr1 = ranges::find_last(rx, 1);
58 VERIFY( ranges::equal(sr1, (int[]){1, 2, 3}) );
59 VERIFY( sr1.begin().ptr == &x[6] );
61 auto sr2 = ranges::find_last(rx, 2);
62 VERIFY( ranges::equal(sr2, (int[]){2, 3}) );
63 VERIFY( sr2.begin().ptr == &x[7] );
65 auto sr3 = ranges::find_last(rx, 3);
66 VERIFY( ranges::equal(sr3, (int[]){3}) );
67 VERIFY( sr3.begin().ptr == &x[8] );
69 auto plus4 = [](int n) { return n+4; };
71 auto sr4 = ranges::find_last(rx, 4, plus4);
72 VERIFY( ranges::empty(sr4) );
73 VERIFY( sr4.begin() == ranges::end(rx) );
75 auto sr5 = ranges::find_last(rx, 5, plus4);
76 VERIFY( ranges::equal(sr5, (int[]){1, 2, 3}) );
77 VERIFY( sr5.begin().ptr == &x[6] );
79 auto sr6 = ranges::find_last(rx, 6, plus4);
80 VERIFY( ranges::equal(sr6, (int[]){2, 3}) );
81 VERIFY( sr6.begin().ptr == &x[7] );
83 auto sr7 = ranges::find_last(rx, 7, plus4);
84 VERIFY( ranges::equal(sr7, (int[]){3}) );
85 VERIFY( sr7.begin().ptr == &x[8] );
88 int
89 main()
91 static_assert(test01());
92 test02();