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