]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/25_algorithms/partition_point/constrained.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / partition_point / constrained.cc
CommitLineData
83ffe9cd 1// Copyright (C) 2020-2023 Free Software Foundation, Inc.
bc464641
PP
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-options "-std=gnu++2a" }
19// { dg-do run { target c++2a } }
20
21#include <algorithm>
22#include <testsuite_hooks.h>
23#include <testsuite_iterators.h>
24
25using __gnu_test::test_container;
26using __gnu_test::test_range;
27using __gnu_test::forward_iterator_wrapper;
28
29namespace ranges = std::ranges;
30
31void
32test01()
33{
34 for (int k = 1; k <= 7; k++)
35 {
36 int x[] = {1,2,3,4,5,6,7};
37 test_container<int, forward_iterator_wrapper> cx(x);
38 auto pred = [&] (int a) { return a <= k; };
39 auto middle = ranges::partition_point(cx, pred);
40 VERIFY( middle.ptr == x+k );
41 }
42
43 for (int k = 1; k <= 8; k++)
44 {
45 int x[] = {1,2,3,4,5,6,7,8};
46 test_range<int, forward_iterator_wrapper> rx(x);
47 auto pred = [&] (int a) { return a > -k; };
48 auto proj = [] (int a) { return -a; };
49 auto middle = ranges::partition_point(rx, pred, proj);
50 VERIFY( middle.ptr == x+k-1 );
51 }
52}
53
54constexpr bool
55test02()
56{
57 int x[] = {1,2,3,4,5};
58 return (ranges::partition_point(x, x+5, [] (int a) { return a < 6; }) == x+5
59 && ranges::partition_point(x, x+5, [] (int a) { return a < 0; }) == x);
60}
61
62int
63main()
64{
65 test01();
66 static_assert(test02());
67}