]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/remove_if/constrained.cc
1 // Copyright (C) 2020-2022 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-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
22 #include <testsuite_hooks.h>
23 #include <testsuite_iterators.h>
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
;
31 namespace ranges
= std::ranges
;
41 int x
[5] = { 1, 2, 3, 4, 5 };
42 const int y
[4] = { 1, 2, 4, 5 };
43 auto res
= ranges::remove_if(x
, [] (int a
) { return a
== 3; });
44 VERIFY( res
.begin() == x
+4 && res
.end() == x
+5 );
45 VERIFY( ranges::equal(x
, x
+4, y
, y
+4) );
52 test_container
<int, forward_iterator_wrapper
> c(x
, x
);
53 auto res
= ranges::remove_if(c
, [] (int a
) { return a
== 1; });
54 VERIFY( res
.begin().ptr
== x
&& res
.end().ptr
== x
);
61 test_container
<int, forward_iterator_wrapper
> c(x
);
62 auto res
= ranges::remove_if(c
, [] (int a
) { return a
== 0; });
63 VERIFY( res
.begin().ptr
== x
+1 && res
.end().ptr
== x
+1 );
64 res
= ranges::remove_if(c
, [] (int a
) { return a
== 1; });
65 VERIFY( res
.begin().ptr
== x
&& res
.end().ptr
== x
+1 );
71 X x
[8] = { {0}, {1}, {0}, {1}, {0}, {0}, {1}, {1} };
72 const int y
[4] = { 0, 0, 0, 0 };
73 test_range
<X
, forward_iterator_wrapper
> c(x
);
74 auto res
= ranges::remove_if(c
, [] (int a
) { return a
== 1; }, &X::i
);
75 VERIFY( res
.begin().ptr
== x
+4 && res
.end().ptr
== x
+8 );
76 VERIFY( ranges::equal(x
, x
+4, y
, y
+4, {}, &X::i
) );
82 int x
[6] = { 3, 2, 3, 3, 5, 3 };
83 const int y
[2] = { 2, 5 };
84 auto res
= ranges::remove_if(x
, [] (int a
) { return a
== 3; });
85 return ranges::equal(x
, res
.begin(), y
, y
+2);
96 static_assert(test05());