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 // <map> 11 12 // class multimap 13 14 // size_type erase(const key_type& k); 15 16 #include <map> 17 #include <cassert> 18 19 #include "min_allocator.h" 20 21 int main() 22 { 23 { 24 typedef std::multimap<int, double> M; 25 typedef std::pair<int, double> P; 26 typedef M::size_type I; 27 P ar[] = 28 { 29 P(1, 1), 30 P(1, 1.5), 31 P(1, 2), 32 P(2, 1), 33 P(2, 1.5), 34 P(2, 2), 35 P(3, 1), 36 P(3, 1.5), 37 P(3, 2), 38 }; 39 M m(ar, ar + sizeof(ar)/sizeof(ar[0])); 40 assert(m.size() == 9); 41 I i = m.erase(2); 42 assert(m.size() == 6); 43 assert(i == 3); 44 assert(next(m.begin(), 0)->first == 1); 45 assert(next(m.begin(), 0)->second == 1); 46 assert(next(m.begin(), 1)->first == 1); 47 assert(next(m.begin(), 1)->second == 1.5); 48 assert(next(m.begin(), 2)->first == 1); 49 assert(next(m.begin(), 2)->second == 2); 50 assert(next(m.begin(), 3)->first == 3); 51 assert(next(m.begin(), 3)->second == 1); 52 assert(next(m.begin(), 4)->first == 3); 53 assert(next(m.begin(), 4)->second == 1.5); 54 assert(next(m.begin(), 5)->first == 3); 55 assert(next(m.begin(), 5)->second == 2); 56 57 i = m.erase(2); 58 assert(m.size() == 6); 59 assert(i == 0); 60 assert(next(m.begin(), 0)->first == 1); 61 assert(next(m.begin(), 0)->second == 1); 62 assert(next(m.begin(), 1)->first == 1); 63 assert(next(m.begin(), 1)->second == 1.5); 64 assert(next(m.begin(), 2)->first == 1); 65 assert(next(m.begin(), 2)->second == 2); 66 assert(next(m.begin(), 3)->first == 3); 67 assert(next(m.begin(), 3)->second == 1); 68 assert(next(m.begin(), 4)->first == 3); 69 assert(next(m.begin(), 4)->second == 1.5); 70 assert(next(m.begin(), 5)->first == 3); 71 assert(next(m.begin(), 5)->second == 2); 72 73 i = m.erase(3); 74 assert(m.size() == 3); 75 assert(next(m.begin(), 0)->first == 1); 76 assert(next(m.begin(), 0)->second == 1); 77 assert(next(m.begin(), 1)->first == 1); 78 assert(next(m.begin(), 1)->second == 1.5); 79 assert(next(m.begin(), 2)->first == 1); 80 assert(next(m.begin(), 2)->second == 2); 81 82 i = m.erase(1); 83 assert(m.size() == 0); 84 assert(i == 3); 85 } 86 #if __cplusplus >= 201103L 87 { 88 typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; 89 typedef std::pair<int, double> P; 90 typedef M::size_type I; 91 P ar[] = 92 { 93 P(1, 1), 94 P(1, 1.5), 95 P(1, 2), 96 P(2, 1), 97 P(2, 1.5), 98 P(2, 2), 99 P(3, 1), 100 P(3, 1.5), 101 P(3, 2), 102 }; 103 M m(ar, ar + sizeof(ar)/sizeof(ar[0])); 104 assert(m.size() == 9); 105 I i = m.erase(2); 106 assert(m.size() == 6); 107 assert(i == 3); 108 assert(next(m.begin(), 0)->first == 1); 109 assert(next(m.begin(), 0)->second == 1); 110 assert(next(m.begin(), 1)->first == 1); 111 assert(next(m.begin(), 1)->second == 1.5); 112 assert(next(m.begin(), 2)->first == 1); 113 assert(next(m.begin(), 2)->second == 2); 114 assert(next(m.begin(), 3)->first == 3); 115 assert(next(m.begin(), 3)->second == 1); 116 assert(next(m.begin(), 4)->first == 3); 117 assert(next(m.begin(), 4)->second == 1.5); 118 assert(next(m.begin(), 5)->first == 3); 119 assert(next(m.begin(), 5)->second == 2); 120 121 i = m.erase(2); 122 assert(m.size() == 6); 123 assert(i == 0); 124 assert(next(m.begin(), 0)->first == 1); 125 assert(next(m.begin(), 0)->second == 1); 126 assert(next(m.begin(), 1)->first == 1); 127 assert(next(m.begin(), 1)->second == 1.5); 128 assert(next(m.begin(), 2)->first == 1); 129 assert(next(m.begin(), 2)->second == 2); 130 assert(next(m.begin(), 3)->first == 3); 131 assert(next(m.begin(), 3)->second == 1); 132 assert(next(m.begin(), 4)->first == 3); 133 assert(next(m.begin(), 4)->second == 1.5); 134 assert(next(m.begin(), 5)->first == 3); 135 assert(next(m.begin(), 5)->second == 2); 136 137 i = m.erase(3); 138 assert(m.size() == 3); 139 assert(next(m.begin(), 0)->first == 1); 140 assert(next(m.begin(), 0)->second == 1); 141 assert(next(m.begin(), 1)->first == 1); 142 assert(next(m.begin(), 1)->second == 1.5); 143 assert(next(m.begin(), 2)->first == 1); 144 assert(next(m.begin(), 2)->second == 2); 145 146 i = m.erase(1); 147 assert(m.size() == 0); 148 assert(i == 3); 149 } 150 #endif 151 } 152