d: Merge dmd, druntime c7902293d7, phobos 03aeafd20
[gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / partition_point / constrained.cc
blob890cdbe4fc53f7eef157bc6dc40089964c5bf99f
1 // Copyright (C) 2020-2025 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.
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 } }
20 #include <algorithm>
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;
30 void
31 test01()
33 for (int k = 1; k <= 7; k++)
35 int x[] = {1,2,3,4,5,6,7};
36 test_container<int, forward_iterator_wrapper> cx(x);
37 auto pred = [&] (int a) { return a <= k; };
38 auto middle = ranges::partition_point(cx, pred);
39 VERIFY( middle.ptr == x+k );
42 for (int k = 1; k <= 8; k++)
44 int x[] = {1,2,3,4,5,6,7,8};
45 test_range<int, forward_iterator_wrapper> rx(x);
46 auto pred = [&] (int a) { return a > -k; };
47 auto proj = [] (int a) { return -a; };
48 auto middle = ranges::partition_point(rx, pred, proj);
49 VERIFY( middle.ptr == x+k-1 );
53 constexpr bool
54 test02()
56 int x[] = {1,2,3,4,5};
57 return (ranges::partition_point(x, x+5, [] (int a) { return a < 6; }) == x+5
58 && ranges::partition_point(x, x+5, [] (int a) { return a < 0; }) == x);
61 int
62 main()
64 test01();
65 static_assert(test02());