]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/equal_range/constrained.cc
1 // Copyright (C) 2020-2022 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-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
22 #include <testsuite_hooks.h>
23 #include <testsuite_iterators.h>
25 using __gnu_test::test_container
;
26 using __gnu_test::test_range
;
27 using __gnu_test::forward_iterator_wrapper
;
29 namespace ranges
= std::ranges
;
34 int x
[] = {1, 2, 3, 4, 5, 5, 6, 7};
35 for (unsigned i
= 0; i
< 5; i
++)
36 for (unsigned j
= 6; j
< 8; j
++)
38 test_container
<int, forward_iterator_wrapper
> cx(x
);
39 auto range
= ranges::equal_range(std::next(cx
.begin(), i
),
40 std::next(cx
.begin(), j
),
41 4, {}, [] (int a
) { return a
-1; });
42 VERIFY( range
.begin().ptr
== x
+4 && range
.end().ptr
== x
+6 );
46 test_range
<int, forward_iterator_wrapper
> rx(x
);
47 auto range
= ranges::equal_range(rx
, 5, ranges::greater
{},
48 [] (int a
) { return a
+1; });
49 VERIFY( range
.begin().ptr
== x
+4 && range
.end().ptr
== x
+5 );
55 int x
[] = {1, 2, 3, 4, 5};
56 auto range1
= ranges::equal_range(x
, 6);
57 auto range2
= ranges::equal_range(x
, x
, 6);
58 auto range3
= ranges::equal_range(x
, 1);
59 return (range1
.begin() == x
+5 && range1
.end() == x
+5
60 && range2
.begin() == x
&& range2
.end() == x
61 && range3
.begin() == x
&& range3
.end() == x
+1);
68 static_assert(test02());