1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <list> 11 12 // template <class Pred> void remove_if(Pred pred); 13 14 #include <list> 15 #include <cassert> 16 #include <functional> 17 18 #include "min_allocator.h" 19 #include "counting_predicates.hpp" 20 21 bool even(int i) 22 { 23 return i % 2 == 0; 24 } 25 26 bool g(int i) 27 { 28 return i < 3; 29 } 30 31 typedef unary_counting_predicate<bool(*)(int), int> Predicate; 32 33 int main() 34 { 35 { 36 int a1[] = {1, 2, 3, 4}; 37 int a2[] = {3, 4}; 38 std::list<int> c(a1, a1+4); 39 Predicate cp(g); 40 c.remove_if(std::ref(cp)); 41 assert(c == std::list<int>(a2, a2+2)); 42 assert(cp.count() == 4); 43 } 44 { 45 int a1[] = {1, 2, 3, 4}; 46 int a2[] = {1, 3}; 47 std::list<int> c(a1, a1+4); 48 Predicate cp(even); 49 c.remove_if(std::ref(cp)); 50 assert(c == std::list<int>(a2, a2+2)); 51 assert(cp.count() == 4); 52 } 53 #if TEST_STD_VER >= 11 54 { 55 int a1[] = {1, 2, 3, 4}; 56 int a2[] = {3, 4}; 57 std::list<int, min_allocator<int>> c(a1, a1+4); 58 Predicate cp(g); 59 c.remove_if(std::ref(cp)); 60 assert((c == std::list<int, min_allocator<int>>(a2, a2+2))); 61 assert(cp.count() == 4); 62 } 63 #endif 64 } 65