| 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_is_permutation() |
| 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::is_permutation(r1.begin(), r1.end(), r2.begin(), r2.end()) ); |
| 23 |
|
| 24 |
std::ranges::equal_to pred; |
| 25 |
VERIFY( ! std::is_permutation(r1.begin(), r1.end(), r2.begin(), r2.end(), |
| 26 |
pred) ); |
| 27 |
} |
| 28 |
|
| 29 |
void |
| 30 |
test_std_ranges_is_permutation() |
| 31 |
{ |
| 32 |
X vals[3]; |
| 33 |
__gnu_test::test_random_access_range<X> r1(vals, vals+3); |
| 34 |
__gnu_test::test_random_access_range<X> r2(vals, vals+2); |
| 35 |
|
| 36 |
// Any application of the projection will cause the test to fail. |
| 37 |
auto proj = [](const X&) -> const X& { VERIFY(false); }; |
| 38 |
VERIFY( ! std::ranges::is_permutation(r1.begin(), r1.end(), |
| 39 |
r2.begin(), r2.end(), |
| 40 |
{}, proj, proj) ); |
| 41 |
|
| 42 |
__gnu_test::test_forward_sized_range<X> r3(vals, vals+3); |
| 43 |
__gnu_test::test_forward_sized_range<X> r4(vals, vals+2); |
| 44 |
VERIFY( ! std::ranges::is_permutation(r3, r4, {}, proj, proj) ); |
| 45 |
} |
| 46 |
|
| 47 |
int main() |
| 48 |
{ |
| 49 |
test_std_is_permutation(); |
| 50 |
test_std_ranges_is_permutation(); |
| 51 |
} |