Debian Codegraph @

libstdc++-v3/testsuite/25_algorithms/equal/lwg3560.cc

raw
1 // { dg-do run { target c++20 } }
2
3 // LWG 3560. ranges::equal and ranges::is_permutation should short-circuit
4 // for sized_ranges
5
6 #include <algorithm>
7 #include <testsuite_iterators.h>
8 #include <testsuite_hooks.h>
9
10 struct X
11 {
12 // Any equality comparison will cause the test to fail.
13 bool operator==(const X&) const { VERIFY(false); }
14 };
15
16 void
17 test_std_equal()
18 {
19 X vals[3];
20 __gnu_test::random_access_container<X> r1(vals, vals+3);
21 __gnu_test::random_access_container<X> r2(vals, vals+2);
22 VERIFY( ! std::equal(r1.begin(), r1.end(), r2.begin(), r2.end()) );
23
24 std::ranges::equal_to pred;
25 VERIFY( ! std::equal(r1.begin(), r1.end(), r2.begin(), r2.end(), pred) );
26 }
27
28 void
29 test_std_ranges_equal()
30 {
31 X vals[3];
32 __gnu_test::test_random_access_range<X> r1(vals, vals+3);
33 __gnu_test::test_random_access_range<X> r2(vals, vals+2);
34
35 // Any application of the projection will cause the test to fail.
36 auto proj = [](const X&) -> const X& { VERIFY(false); };
37 VERIFY( ! std::ranges::equal(r1.begin(), r1.end(), r2.begin(), r2.end(), {},
38 proj, proj) );
39
40 __gnu_test::test_forward_sized_range<X> r3(vals, vals+3);
41 __gnu_test::test_forward_sized_range<X> r4(vals, vals+2);
42 VERIFY( ! std::ranges::equal(r3, r4, {}, proj, proj) );
43 }
44
45 int main()
46 {
47 test_std_equal();
48 test_std_ranges_equal();
49 }