erase_if.pass.cpp (2709B)
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 // <unordered_map> 12 13 // template <class Key, class T, class Hash, class Pred, class Allocator, class Predicate> 14 // void erase_if(unordered_multimap<Key, T, Hash, Pred, Allocator>& c, Predicate pred); 15 16 #include <unordered_map> 17 18 #include "test_macros.h" 19 #include "test_allocator.h" 20 #include "min_allocator.h" 21 22 using Init = std::initializer_list<int>; 23 template <typename M> 24 M make (Init vals) 25 { 26 M ret; 27 for (int v : vals) 28 ret.insert(typename M::value_type(v, v + 10)); 29 return ret; 30 } 31 32 template <typename M, typename Pred> 33 void 34 test0(Init vals, Pred p, Init expected) 35 { 36 M s = make<M> (vals); 37 ASSERT_SAME_TYPE(void, decltype(std::erase_if(s, p))); 38 std::erase_if(s, p); 39 M e = make<M>(expected); 40 assert((std::is_permutation(s.begin(), s.end(), e.begin(), e.end()))); 41 } 42 43 template <typename S> 44 void test() 45 { 46 auto is1 = [](auto v) { return v.first == 1;}; 47 auto is2 = [](auto v) { return v.first == 2;}; 48 auto is3 = [](auto v) { return v.first == 3;}; 49 auto is4 = [](auto v) { return v.first == 4;}; 50 auto True = [](auto) { return true; }; 51 auto False = [](auto) { return false; }; 52 53 test0<S>({}, is1, {}); 54 55 test0<S>({1}, is1, {}); 56 test0<S>({1}, is2, {1}); 57 58 test0<S>({1,2}, is1, {2}); 59 test0<S>({1,2}, is2, {1}); 60 test0<S>({1,2}, is3, {1,2}); 61 test0<S>({1,1}, is1, {}); 62 test0<S>({1,1}, is3, {1,1}); 63 64 test0<S>({1,2,3}, is1, {2,3}); 65 test0<S>({1,2,3}, is2, {1,3}); 66 test0<S>({1,2,3}, is3, {1,2}); 67 test0<S>({1,2,3}, is4, {1,2,3}); 68 69 test0<S>({1,1,1}, is1, {}); 70 test0<S>({1,1,1}, is2, {1,1,1}); 71 test0<S>({1,1,2}, is1, {2}); 72 test0<S>({1,1,2}, is2, {1,1}); 73 test0<S>({1,1,2}, is3, {1,1,2}); 74 test0<S>({1,2,2}, is1, {2,2}); 75 test0<S>({1,2,2}, is2, {1}); 76 test0<S>({1,2,2}, is3, {1,2,2}); 77 78 test0<S>({1,2,3}, True, {}); 79 test0<S>({1,2,3}, False, {1,2,3}); 80 } 81 82 int main() 83 { 84 test<std::unordered_multimap<int, int>>(); 85 test<std::unordered_multimap<int, int, std::hash<int>, std::equal_to<int>, min_allocator<std::pair<const int, int>>>> (); 86 test<std::unordered_multimap<int, int, std::hash<int>, std::equal_to<int>, test_allocator<std::pair<const int, int>>>> (); 87 88 test<std::unordered_multimap<long, short>>(); 89 test<std::unordered_multimap<short, double>>(); 90 }