OpenMP: Fix typo in atomic directive error message
[gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / remove_if / constrained.cc
blob70631fdebdc3a7d49b693399ccc0175571168215
1 // Copyright (C) 2020-2025 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.
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 } }
20 #include <algorithm>
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;
32 struct X
34 int i;
37 void
38 test01()
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) );
47 void
48 test02()
50 int x[1];
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 );
56 void
57 test03()
59 int x[1] = {1};
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 );
67 void
68 test04()
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) );
78 constexpr bool
79 test05()
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);
88 int
89 main()
91 test01();
92 test02();
93 test03();
94 test04();
95 static_assert(test05());