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