]>
Commit | Line | Data |
---|---|---|
1 | // Copyright (C) 2020-2024 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 | struct X | |
33 | { | |
34 | int i; | |
35 | }; | |
36 | ||
37 | void | |
38 | test01() | |
39 | { | |
40 | int x[5] = { 1, 2, 3, 4, 5 }; | |
41 | const int y[4] = { 1, 2, 4, 5 }; | |
42 | auto res = ranges::remove(x, 3); | |
43 | VERIFY( res.begin() == x+4 && res.end() == x+5 ); | |
44 | VERIFY( ranges::equal(x, x+4, y, y+4) ); | |
45 | } | |
46 | ||
47 | void | |
48 | test02() | |
49 | { | |
50 | int x[1]; | |
51 | test_container<int, forward_iterator_wrapper> c(x, x); | |
52 | auto res = ranges::remove(c, 1); | |
53 | VERIFY( res.begin().ptr == x && res.end().ptr == x ); | |
54 | } | |
55 | ||
56 | void | |
57 | test03() | |
58 | { | |
59 | int x[1] = {1}; | |
60 | test_container<int, forward_iterator_wrapper> c(x); | |
61 | auto res = ranges::remove(c, 0); | |
62 | VERIFY( res.begin().ptr == x+1 && res.end().ptr == x+1 ); | |
63 | res = ranges::remove(c, 1); | |
64 | VERIFY( res.begin().ptr == x && res.end().ptr == x+1 ); | |
65 | } | |
66 | ||
67 | void | |
68 | test04() | |
69 | { | |
70 | X x[8] = { {0}, {1}, {0}, {1}, {0}, {0}, {1}, {1} }; | |
71 | const int y[4] = { 0, 0, 0, 0 }; | |
72 | test_container<X, forward_iterator_wrapper> c(x); | |
73 | auto res = ranges::remove(c, 1, &X::i); | |
74 | VERIFY( res.begin().ptr == x+4 && res.end().ptr == x+8 ); | |
75 | VERIFY( ranges::equal(x, x+4, y, y+4, {}, &X::i) ); | |
76 | } | |
77 | ||
78 | constexpr bool | |
79 | test05() | |
80 | { | |
81 | int x[6] = { 3, 2, 3, 3, 5, 3 }; | |
82 | const int y[2] = { 2, 5 }; | |
83 | auto res = ranges::remove(x, 3); | |
84 | return ranges::equal(x, res.begin(), y, y+2); | |
85 | } | |
86 | ||
87 | ||
88 | int | |
89 | main() | |
90 | { | |
91 | test01(); | |
92 | test02(); | |
93 | test03(); | |
94 | test04(); | |
95 | static_assert(test05()); | |
96 | } |