erase_if.pass.cpp (2140B)
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 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 10 11 // <deque> 12 13 // template <class T, class Allocator, class Predicate> 14 // void erase_if(deque<T, Allocator>& c, Predicate pred); 15 16 #include <deque> 17 18 #include "test_macros.h" 19 #include "test_allocator.h" 20 #include "min_allocator.h" 21 22 template <class S, class Pred> 23 void 24 test0(S s, Pred p, S expected) 25 { 26 ASSERT_SAME_TYPE(void, decltype(std::erase_if(s, p))); 27 std::erase_if(s, p); 28 assert(s == expected); 29 } 30 31 template <typename S> 32 void test() 33 { 34 auto is1 = [](auto v) { return v == 1;}; 35 auto is2 = [](auto v) { return v == 2;}; 36 auto is3 = [](auto v) { return v == 3;}; 37 auto is4 = [](auto v) { return v == 4;}; 38 auto True = [](auto) { return true; }; 39 auto False = [](auto) { return false; }; 40 41 test0(S(), is1, S()); 42 43 test0(S({1}), is1, S()); 44 test0(S({1}), is2, S({1})); 45 46 test0(S({1,2}), is1, S({2})); 47 test0(S({1,2}), is2, S({1})); 48 test0(S({1,2}), is3, S({1,2})); 49 test0(S({1,1}), is1, S()); 50 test0(S({1,1}), is3, S({1,1})); 51 52 test0(S({1,2,3}), is1, S({2,3})); 53 test0(S({1,2,3}), is2, S({1,3})); 54 test0(S({1,2,3}), is3, S({1,2})); 55 test0(S({1,2,3}), is4, S({1,2,3})); 56 57 test0(S({1,1,1}), is1, S()); 58 test0(S({1,1,1}), is2, S({1,1,1})); 59 test0(S({1,1,2}), is1, S({2})); 60 test0(S({1,1,2}), is2, S({1,1})); 61 test0(S({1,1,2}), is3, S({1,1,2})); 62 test0(S({1,2,2}), is1, S({2,2})); 63 test0(S({1,2,2}), is2, S({1})); 64 test0(S({1,2,2}), is3, S({1,2,2})); 65 66 test0(S({1,2,3}), True, S()); 67 test0(S({1,2,3}), False, S({1,2,3})); 68 } 69 70 int main() 71 { 72 test<std::deque<int>>(); 73 test<std::deque<int, min_allocator<int>>> (); 74 test<std::deque<int, test_allocator<int>>> (); 75 76 test<std::deque<long>>(); 77 test<std::deque<double>>(); 78 }