1 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do run { target c++20 } }
21 #include <testsuite_hooks.h>
22 #include <testsuite_iterators.h>
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
;
30 namespace ranges
= std::ranges
;
40 int x
[5] = { 1, 2, 3, 4, 5 };
41 const int y
[4] = { 1, 2, 4, 5 };
42 auto res
= ranges::remove_if(x
, [] (int a
) { return a
== 3; });
43 VERIFY( res
.begin() == x
+4 && res
.end() == x
+5 );
44 VERIFY( ranges::equal(x
, x
+4, y
, y
+4) );
51 test_container
<int, forward_iterator_wrapper
> c(x
, x
);
52 auto res
= ranges::remove_if(c
, [] (int a
) { return a
== 1; });
53 VERIFY( res
.begin().ptr
== x
&& res
.end().ptr
== x
);
60 test_container
<int, forward_iterator_wrapper
> c(x
);
61 auto res
= ranges::remove_if(c
, [] (int a
) { return a
== 0; });
62 VERIFY( res
.begin().ptr
== x
+1 && res
.end().ptr
== x
+1 );
63 res
= ranges::remove_if(c
, [] (int a
) { return a
== 1; });
64 VERIFY( res
.begin().ptr
== x
&& res
.end().ptr
== x
+1 );
70 X x
[8] = { {0}, {1}, {0}, {1}, {0}, {0}, {1}, {1} };
71 const int y
[4] = { 0, 0, 0, 0 };
72 test_range
<X
, forward_iterator_wrapper
> c(x
);
73 auto res
= ranges::remove_if(c
, [] (int a
) { return a
== 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
) );
81 int x
[6] = { 3, 2, 3, 3, 5, 3 };
82 const int y
[2] = { 2, 5 };
83 auto res
= ranges::remove_if(x
, [] (int a
) { return a
== 3; });
84 return ranges::equal(x
, res
.begin(), y
, y
+2);
95 static_assert(test05());