1 // Copyright (C) 2020-2025 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 } }
21 #include <testsuite_hooks.h>
22 #include <testsuite_iterators.h>
24 using __gnu_test::test_container
;
25 using __gnu_test::test_range
;
26 using __gnu_test::forward_iterator_wrapper
;
28 namespace ranges
= std::ranges
;
33 int x
[] = {1, 2, 3, 4, 5, 5, 6, 7};
34 for (unsigned i
= 0; i
< 5; i
++)
35 for (unsigned j
= 6; j
< 8; j
++)
37 test_container
<int, forward_iterator_wrapper
> cx(x
);
38 auto range
= ranges::equal_range(std::next(cx
.begin(), i
),
39 std::next(cx
.begin(), j
),
40 4, {}, [] (int a
) { return a
-1; });
41 VERIFY( range
.begin().ptr
== x
+4 && range
.end().ptr
== x
+6 );
45 test_range
<int, forward_iterator_wrapper
> rx(x
);
46 auto range
= ranges::equal_range(rx
, 5, ranges::greater
{},
47 [] (int a
) { return a
+1; });
48 VERIFY( range
.begin().ptr
== x
+4 && range
.end().ptr
== x
+5 );
54 int x
[] = {1, 2, 3, 4, 5};
55 auto range1
= ranges::equal_range(x
, 6);
56 auto range2
= ranges::equal_range(x
, x
, 6);
57 auto range3
= ranges::equal_range(x
, 1);
58 return (range1
.begin() == x
+5 && range1
.end() == x
+5
59 && range2
.begin() == x
&& range2
.end() == x
60 && range3
.begin() == x
&& range3
.end() == x
+1);
67 static_assert(test02());