]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/equal_range/constrained.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / equal_range / constrained.cc
1 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
2 //
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)
7 // any later version.
8
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.
13
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/>.
17
18 // { dg-do run { target c++20 } }
19
20 #include <algorithm>
21 #include <testsuite_hooks.h>
22 #include <testsuite_iterators.h>
23
24 using __gnu_test::test_container;
25 using __gnu_test::test_range;
26 using __gnu_test::forward_iterator_wrapper;
27
28 namespace ranges = std::ranges;
29
30 void
31 test01()
32 {
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++)
36 {
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 );
42 }
43
44 ranges::reverse(x);
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 );
49 }
50
51 constexpr bool
52 test02()
53 {
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);
61 }
62
63 int
64 main()
65 {
66 test01();
67 static_assert(test02());
68 }