]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/lexicographical_compare/constrained.cc
1 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do run { target c++20 } }
19 // { dg-require-effective-target hosted }
23 #include <testsuite_hooks.h>
24 #include <testsuite_iterators.h>
26 using __gnu_test::test_container
;
27 using __gnu_test::test_range
;
28 using __gnu_test::input_iterator_wrapper
;
29 using __gnu_test::forward_iterator_wrapper
;
31 namespace ranges
= std::ranges
;
36 int x
[] = {1, 2, 3, 4, 5};
37 char y
[] = {1, 2, 3, 5};
38 long z
[] = {1, 2, 3, 4, 5, 6};
41 test_range
<int, input_iterator_wrapper
> rx(x
);
42 test_range
<char, input_iterator_wrapper
> ry(y
);
43 test_range
<long, input_iterator_wrapper
> rz(z
);
45 VERIFY( ranges::lexicographical_compare(rx
, ry
) );
48 VERIFY( !ranges::lexicographical_compare(ry
, rx
) );
51 test_range
<int, forward_iterator_wrapper
> rx(x
);
52 test_range
<char, forward_iterator_wrapper
> ry(y
);
53 test_range
<long, forward_iterator_wrapper
> rz(z
);
55 VERIFY( ranges::lexicographical_compare(rx
, rz
) );
56 VERIFY( !ranges::lexicographical_compare(rz
, rx
) );
58 VERIFY( !ranges::lexicographical_compare(rx
, rx
) );
59 VERIFY( ranges::lexicographical_compare(rx
, rx
, {}, std::negate
<>{}) );
60 VERIFY( ranges::lexicographical_compare(rx
, rx
, std::greater
{},
61 {}, std::negate
<>{}) );
63 VERIFY( !ranges::lexicographical_compare(rx
, ry
, {},
66 VERIFY( ranges::lexicographical_compare(ry
, rx
, {},
70 VERIFY( ranges::lexicographical_compare(rx
, rz
, ranges::greater
{}) );
71 VERIFY( !ranges::lexicographical_compare(rz
, rx
, ranges::greater
{}) );
73 VERIFY( ranges::lexicographical_compare(rx
, ry
, ranges::greater
{},
76 VERIFY( !ranges::lexicographical_compare(ry
, rx
, ranges::greater
{},
84 int x
[] = {1, 2, 3, 4, 5};
85 int y
[] = {1, 2, 3, 5};
86 int z
[] = {1, 2, 3, 4, 5, 6};
88 VERIFY( ranges::lexicographical_compare(x
, y
) );
89 VERIFY( !ranges::lexicographical_compare(y
, x
) );
91 VERIFY( ranges::lexicographical_compare(x
, z
) );
92 VERIFY( !ranges::lexicographical_compare(z
, x
) );
94 VERIFY( !ranges::lexicographical_compare(x
, x
) );
96 VERIFY( !ranges::lexicographical_compare(x
, y
, {},
99 VERIFY( ranges::lexicographical_compare(y
, x
, {},
103 VERIFY( ranges::lexicographical_compare(x
, z
, ranges::greater
{}) );
104 VERIFY( !ranges::lexicographical_compare(z
, x
, ranges::greater
{}) );
106 VERIFY( ranges::lexicographical_compare(x
, y
, ranges::greater
{},
109 VERIFY( !ranges::lexicographical_compare(y
, x
, ranges::greater
{},
117 int x
[] = {1, 2, 3, 4, 5};
118 int y
[] = {1, 2, 5, 3};
119 int z
[] = {1, 2, 3, 5};
123 VERIFY( ranges::lexicographical_compare(x
, y
) );
124 VERIFY( !ranges::lexicographical_compare(x
, y
, ranges::greater
{}) );
125 VERIFY( !ranges::lexicographical_compare(y
, x
) );
126 VERIFY( ranges::lexicographical_compare(y
, x
, ranges::greater
{}) );
128 test_container
<int, forward_iterator_wrapper
> cy(y
);
129 VERIFY( ranges::lexicographical_compare(x
, cy
) );
130 VERIFY( !ranges::lexicographical_compare(x
, cy
, ranges::greater
{}) );
131 VERIFY( !ranges::lexicographical_compare(cy
, x
) );
132 VERIFY( ranges::lexicographical_compare(cy
, x
, ranges::greater
{}) );
134 test_container
<int, forward_iterator_wrapper
> cz(z
);
135 VERIFY( ranges::lexicographical_compare(cz
.begin(), cz
.end(),
136 cy
.begin(), cy
.end()) );
137 VERIFY( !ranges::lexicographical_compare(cy
.begin(), cy
.end(),
138 cz
.begin(), cz
.end()) );
140 std::vector
<int> vx(x
, x
+5), vy(y
, y
+4);
141 VERIFY( ranges::lexicographical_compare(vx
, vy
) );
142 VERIFY( !ranges::lexicographical_compare(vx
, vy
, ranges::greater
{}) );
143 VERIFY( !ranges::lexicographical_compare(vy
, vx
) );
144 VERIFY( ranges::lexicographical_compare(vy
, vx
, ranges::greater
{}) );
145 } while (ranges::next_permutation(y
).found
);
153 return (ranges::lexicographical_compare((int[]){1,2,3,5},
155 && !ranges::lexicographical_compare(x
, x
, y
, y
));
164 static_assert(test04());