1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 #include "counting_predicates.h"
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_
;}
41 typedef unary_counting_predicate
<bool(*)(int), int> Predicate
;
46 int a1
[] = {1, 2, 3, 4};
48 typedef std::list
<int> L
;
52 ASSERT_SAME_TYPE(L::size_type
, decltype(c
.remove_if(std::ref(cp
))));
53 assert(c
.remove_if(std::ref(cp
)) == 2);
55 ASSERT_SAME_TYPE(void, decltype(c
.remove_if(std::ref(cp
))));
56 c
.remove_if(std::ref(cp
));
58 assert(c
== std::list
<int>(a2
, a2
+2));
59 assert(cp
.count() == 4);
62 int a1
[] = {1, 2, 3, 4};
64 std::list
<int> c(a1
, a1
+4);
67 assert(c
.remove_if(std::ref(cp
)) == 2);
69 c
.remove_if(std::ref(cp
));
71 assert(c
== std::list
<int>(a2
, a2
+2));
72 assert(cp
.count() == 4);
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
]);
87 #if TEST_STD_VER >= 11
89 int a1
[] = {1, 2, 3, 4};
91 std::list
<int, min_allocator
<int>> c(a1
, a1
+4);
94 assert(c
.remove_if(std::ref(cp
)) == 2);
96 c
.remove_if(std::ref(cp
));
98 assert((c
== std::list
<int, min_allocator
<int>>(a2
, a2
+2)));
99 assert(cp
.count() == 4);