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