Debian Codegraph @

libstdc++-v3/testsuite/25_algorithms/partition_copy/constrained.cc

raw
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.
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::input_iterator_wrapper;
27 using __gnu_test::output_iterator_wrapper;
28 using __gnu_test::forward_iterator_wrapper;
29
30 namespace ranges = std::ranges;
31
32 void
33 test01()
34 {
35 {
36 int x[] = {1,2,3,4,5,6,7,8,9,10,11};
37 int y[5], z[6];
38 test_container<int, forward_iterator_wrapper> cx(x);
39 test_container<int, forward_iterator_wrapper> cy(y), cz(z);
40 auto pred = [] (int a) { return a%2==0; };
41 auto [in,out_true,out_false]
42 = ranges::partition_copy(cx, cy.begin(), cz.begin(), pred);
43 VERIFY( in.ptr == x+11 );
44 VERIFY( out_true.ptr == y+5 );
45 VERIFY( out_false.ptr == z+6 );
46 VERIFY( ranges::all_of(cy, pred) );
47 VERIFY( ranges::none_of(cz, pred) );
48 }
49
50 {
51 int x[] = {1,2,3,4,5,6,7,8,9,10,11};
52 int y[6], z[5];
53 test_range<int, input_iterator_wrapper> cx(x);
54 test_range<int, output_iterator_wrapper> cy(y), cz(z);
55 auto pred = [] (int a) { return a%2==0; };
56 auto proj = [] (int a) { return a+1; };
57 auto [in,out_true,out_false]
58 = ranges::partition_copy(cx, cy.begin(), cz.begin(), pred, proj);
59 VERIFY( in.ptr == x+11 );
60 VERIFY( out_true.ptr == y+6 );
61 VERIFY( out_false.ptr == z+5 );
62 VERIFY( ranges::none_of(y, pred) );
63 VERIFY( ranges::all_of(z, pred) );
64 }
65 }
66
67 constexpr bool
68 test02()
69 {
70 int x[] = {1,2,3,4,5,6,7,8,9,10};
71 auto range = ranges::partition(x, x+9, [] (int a) { return a < 100; });
72 return (range.begin() == x+9 && range.end() == x+9);
73 }
74
75 int
76 main()
77 {
78 test01();
79 static_assert(test02());
80 }