]>
Commit | Line | Data |
---|---|---|
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 | ||
25 | using __gnu_test::test_container; | |
26 | using __gnu_test::test_range; | |
27 | using __gnu_test::input_iterator_wrapper; | |
28 | using __gnu_test::output_iterator_wrapper; | |
29 | using __gnu_test::forward_iterator_wrapper; | |
30 | ||
31 | namespace ranges = std::ranges; | |
32 | ||
33 | struct X | |
34 | { | |
35 | int i; | |
36 | ||
37 | friend constexpr bool | |
38 | operator==(const X& a, const X& b) | |
39 | { | |
40 | return a.i == b.i; | |
41 | } | |
42 | }; | |
43 | ||
44 | void | |
45 | test01() | |
46 | { | |
47 | { | |
48 | const X x[6] = { {2}, {2}, {6}, {8}, {10}, {11} }; | |
49 | X y[4]; | |
50 | X z[4] = { {2}, {2}, {6}, {10} }; | |
51 | auto [in,out] = ranges::remove_copy(x, x+5, y, 8, &X::i); | |
52 | VERIFY( in == x+5 && out == y+4 ); | |
53 | VERIFY( ranges::equal(y, z) ); | |
54 | } | |
55 | ||
56 | { | |
57 | const X x[6] = { {2}, {2}, {6}, {8}, {10}, {11} }; | |
58 | X y[5]; | |
59 | X z[5] = { {2}, {2}, {6}, {8}, {10} }; | |
60 | auto [in,out] = ranges::remove_copy(x, x+5, y, 11, &X::i); | |
61 | VERIFY( in == x+5 && out == y+5 ); | |
62 | VERIFY( ranges::equal(x, x+5, y, y+5) && ranges::equal(y, z) ); | |
63 | } | |
64 | ||
65 | { | |
66 | X x[6] = { {2}, {2}, {6}, {8}, {10}, {2} }; | |
67 | X y[3]; | |
68 | X z[3] = { {6}, {8}, {10} }; | |
69 | test_container<X, forward_iterator_wrapper> cx(x), cy(y), cz(z); | |
70 | auto [in, out] = ranges::remove_copy(cx, cy.begin(), 2, &X::i); | |
71 | VERIFY( in == cx.end() && out == cy.end() ); | |
72 | VERIFY( ranges::equal(cy, cz) ); | |
73 | } | |
74 | ||
75 | { | |
76 | X x[6] = { {2}, {2}, {6}, {8}, {10}, {11} }; | |
77 | X y[4]; | |
78 | const X z[4] = { {6}, {8}, {10}, {11} }; | |
79 | test_range<X, input_iterator_wrapper> cx(x); | |
80 | test_range<X, output_iterator_wrapper> cy(y); | |
81 | auto [in, out] = ranges::remove_copy(cx, cy.begin(), 2, &X::i); | |
82 | VERIFY( in == cx.end() && out == cy.end() ); | |
83 | VERIFY( ranges::equal(y, z) ); | |
84 | } | |
85 | } | |
86 | ||
87 | struct Y { int i; int j; }; | |
88 | ||
89 | constexpr bool | |
90 | test02() | |
91 | { | |
92 | bool ok = true; | |
93 | Y x[3] = { {3,2}, {2,4}, {3,6} }; | |
94 | Y y[1]; | |
95 | Y z[1] = { {2,4} }; | |
96 | auto [in, out] = ranges::remove_copy(x, y, 3, &Y::i); | |
97 | ok &= in == x+3; | |
98 | ok &= out == y+1; | |
99 | ok &= ranges::equal(y, z, {}, &Y::i, &Y::i); | |
100 | ok &= ranges::equal(y, z, {}, &Y::j, &Y::j); | |
101 | return ok; | |
102 | } | |
103 | ||
104 | int | |
105 | main() | |
106 | { | |
107 | test01(); | |
108 | static_assert(test02()); | |
109 | } |