[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / list / list.ops / remove_if.pass.cpp
blobbe7ff85764cbefffcc3f2ef5d88de87185a67338
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <list>
11 // template <class Pred> void remove_if(Pred pred); // before C++20
12 // template <class Pred> size_type remove_if(Pred pred); // c++20 and later
14 #include <list>
15 #include <cassert>
16 #include <functional>
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 #include "counting_predicates.h"
22 bool even(int i)
24 return i % 2 == 0;
27 bool g(int i)
29 return i < 3;
32 struct PredLWG526 {
33 PredLWG526 (int i) : i_(i) {};
34 ~PredLWG526() { i_ = -32767; }
35 bool operator() (const PredLWG526 &p) const { return p.i_ == i_; }
37 bool operator==(int i) const { return i == i_;}
38 int i_;
41 typedef unary_counting_predicate<bool(*)(int), int> Predicate;
43 int main(int, char**)
46 int a1[] = {1, 2, 3, 4};
47 int a2[] = {3, 4};
48 typedef std::list<int> L;
49 L c(a1, a1+4);
50 Predicate cp(g);
51 #if TEST_STD_VER > 17
52 ASSERT_SAME_TYPE(L::size_type, decltype(c.remove_if(std::ref(cp))));
53 assert(c.remove_if(std::ref(cp)) == 2);
54 #else
55 ASSERT_SAME_TYPE(void, decltype(c.remove_if(std::ref(cp))));
56 c.remove_if(std::ref(cp));
57 #endif
58 assert(c == std::list<int>(a2, a2+2));
59 assert(cp.count() == 4);
62 int a1[] = {1, 2, 3, 4};
63 int a2[] = {1, 3};
64 std::list<int> c(a1, a1+4);
65 Predicate cp(even);
66 #if TEST_STD_VER > 17
67 assert(c.remove_if(std::ref(cp)) == 2);
68 #else
69 c.remove_if(std::ref(cp));
70 #endif
71 assert(c == std::list<int>(a2, a2+2));
72 assert(cp.count() == 4);
74 { // LWG issue #526
75 int a1[] = {1, 2, 1, 3, 5, 8, 11};
76 int a2[] = {2, 3, 5, 8, 11};
77 std::list<PredLWG526> c(a1, a1 + 7);
78 c.remove_if(std::ref(c.front()));
79 assert(c.size() == 5);
80 for (size_t i = 0; i < c.size(); ++i)
82 assert(c.front() == a2[i]);
83 c.pop_front();
87 #if TEST_STD_VER >= 11
89 int a1[] = {1, 2, 3, 4};
90 int a2[] = {3, 4};
91 std::list<int, min_allocator<int>> c(a1, a1+4);
92 Predicate cp(g);
93 #if TEST_STD_VER > 17
94 assert(c.remove_if(std::ref(cp)) == 2);
95 #else
96 c.remove_if(std::ref(cp));
97 #endif
98 assert((c == std::list<int, min_allocator<int>>(a2, a2+2)));
99 assert(cp.count() == 4);
101 #endif
103 return 0;