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