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 // <forward_list> 11 12 // template <class Predicate> void remove_if(Predicate pred); 13 14 #include <forward_list> 15 #include <iterator> 16 #include <cassert> 17 #include <cstddef> 18 19 #include "min_allocator.h" 20 #include "counting_predicates.hpp" 21 22 23 bool g(int i) 24 { 25 return i < 3; 26 } 27 28 int main() 29 { 30 { 31 typedef int T; 32 typedef unary_counting_predicate<bool(*)(T), T> Predicate; 33 typedef std::forward_list<T> C; 34 const T t1[] = {0, 5, 5, 0, 0, 0, 5}; 35 const T t2[] = {5, 5, 5}; 36 C c1(std::begin(t1), std::end(t1)); 37 C c2(std::begin(t2), std::end(t2)); 38 Predicate cp(g); 39 c1.remove_if(std::ref(cp)); 40 assert(c1 == c2); 41 assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1)))); 42 } 43 { 44 typedef int T; 45 typedef unary_counting_predicate<bool(*)(T), T> Predicate; 46 typedef std::forward_list<T> C; 47 const T t1[] = {0, 0, 0, 0}; 48 C c1(std::begin(t1), std::end(t1)); 49 C c2; 50 Predicate cp(g); 51 c1.remove_if(std::ref(cp)); 52 assert(c1 == c2); 53 assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1)))); 54 } 55 { 56 typedef int T; 57 typedef unary_counting_predicate<bool(*)(T), T> Predicate; 58 typedef std::forward_list<T> C; 59 const T t1[] = {5, 5, 5}; 60 const T t2[] = {5, 5, 5}; 61 C c1(std::begin(t1), std::end(t1)); 62 C c2(std::begin(t2), std::end(t2)); 63 Predicate cp(g); 64 c1.remove_if(std::ref(cp)); 65 assert(c1 == c2); 66 assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1)))); 67 } 68 { 69 typedef int T; 70 typedef unary_counting_predicate<bool(*)(T), T> Predicate; 71 typedef std::forward_list<T> C; 72 C c1; 73 C c2; 74 Predicate cp(g); 75 c1.remove_if(std::ref(cp)); 76 assert(c1 == c2); 77 assert(cp.count() == 0); 78 } 79 { 80 typedef int T; 81 typedef unary_counting_predicate<bool(*)(T), T> Predicate; 82 typedef std::forward_list<T> C; 83 const T t1[] = {5, 5, 5, 0}; 84 const T t2[] = {5, 5, 5}; 85 C c1(std::begin(t1), std::end(t1)); 86 C c2(std::begin(t2), std::end(t2)); 87 Predicate cp(g); 88 c1.remove_if(std::ref(cp)); 89 assert(c1 == c2); 90 assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1)))); 91 } 92 #if TEST_STD_VER >= 11 93 { 94 typedef int T; 95 typedef unary_counting_predicate<bool(*)(T), T> Predicate; 96 typedef std::forward_list<T, min_allocator<T>> C; 97 const T t1[] = {0, 5, 5, 0, 0, 0, 5}; 98 const T t2[] = {5, 5, 5}; 99 C c1(std::begin(t1), std::end(t1)); 100 C c2(std::begin(t2), std::end(t2)); 101 Predicate cp(g); 102 c1.remove_if(std::ref(cp)); 103 assert(c1 == c2); 104 assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1)))); 105 } 106 { 107 typedef int T; 108 typedef unary_counting_predicate<bool(*)(T), T> Predicate; 109 typedef std::forward_list<T, min_allocator<T>> C; 110 const T t1[] = {0, 0, 0, 0}; 111 C c1(std::begin(t1), std::end(t1)); 112 C c2; 113 Predicate cp(g); 114 c1.remove_if(std::ref(cp)); 115 assert(c1 == c2); 116 assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1)))); 117 } 118 { 119 typedef int T; 120 typedef unary_counting_predicate<bool(*)(T), T> Predicate; 121 typedef std::forward_list<T, min_allocator<T>> C; 122 const T t1[] = {5, 5, 5}; 123 const T t2[] = {5, 5, 5}; 124 C c1(std::begin(t1), std::end(t1)); 125 C c2(std::begin(t2), std::end(t2)); 126 Predicate cp(g); 127 c1.remove_if(std::ref(cp)); 128 assert(c1 == c2); 129 assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1)))); 130 } 131 { 132 typedef int T; 133 typedef unary_counting_predicate<bool(*)(T), T> Predicate; 134 typedef std::forward_list<T, min_allocator<T>> C; 135 C c1; 136 C c2; 137 Predicate cp(g); 138 c1.remove_if(std::ref(cp)); 139 assert(c1 == c2); 140 assert(cp.count() == 0); 141 } 142 { 143 typedef int T; 144 typedef unary_counting_predicate<bool(*)(T), T> Predicate; 145 typedef std::forward_list<T, min_allocator<T>> C; 146 const T t1[] = {5, 5, 5, 0}; 147 const T t2[] = {5, 5, 5}; 148 C c1(std::begin(t1), std::end(t1)); 149 C c2(std::begin(t2), std::end(t2)); 150 Predicate cp(g); 151 c1.remove_if(std::ref(cp)); 152 assert(c1 == c2); 153 assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1)))); 154 } 155 #endif 156 } 157