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