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 
main()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(i == 3);
75         assert(m.size() == 3);
76         assert(next(m.begin(), 0)->first == 1);
77         assert(next(m.begin(), 0)->second == 1);
78         assert(next(m.begin(), 1)->first == 1);
79         assert(next(m.begin(), 1)->second == 1.5);
80         assert(next(m.begin(), 2)->first == 1);
81         assert(next(m.begin(), 2)->second == 2);
82 
83         i = m.erase(1);
84         assert(m.size() == 0);
85         assert(i == 3);
86     }
87 #if __cplusplus >= 201103L
88     {
89         typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
90         typedef std::pair<int, double> P;
91         typedef M::size_type I;
92         P ar[] =
93         {
94             P(1, 1),
95             P(1, 1.5),
96             P(1, 2),
97             P(2, 1),
98             P(2, 1.5),
99             P(2, 2),
100             P(3, 1),
101             P(3, 1.5),
102             P(3, 2),
103         };
104         M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
105         assert(m.size() == 9);
106         I i = m.erase(2);
107         assert(m.size() == 6);
108         assert(i == 3);
109         assert(next(m.begin(), 0)->first == 1);
110         assert(next(m.begin(), 0)->second == 1);
111         assert(next(m.begin(), 1)->first == 1);
112         assert(next(m.begin(), 1)->second == 1.5);
113         assert(next(m.begin(), 2)->first == 1);
114         assert(next(m.begin(), 2)->second == 2);
115         assert(next(m.begin(), 3)->first == 3);
116         assert(next(m.begin(), 3)->second == 1);
117         assert(next(m.begin(), 4)->first == 3);
118         assert(next(m.begin(), 4)->second == 1.5);
119         assert(next(m.begin(), 5)->first == 3);
120         assert(next(m.begin(), 5)->second == 2);
121 
122         i = m.erase(2);
123         assert(m.size() == 6);
124         assert(i == 0);
125         assert(next(m.begin(), 0)->first == 1);
126         assert(next(m.begin(), 0)->second == 1);
127         assert(next(m.begin(), 1)->first == 1);
128         assert(next(m.begin(), 1)->second == 1.5);
129         assert(next(m.begin(), 2)->first == 1);
130         assert(next(m.begin(), 2)->second == 2);
131         assert(next(m.begin(), 3)->first == 3);
132         assert(next(m.begin(), 3)->second == 1);
133         assert(next(m.begin(), 4)->first == 3);
134         assert(next(m.begin(), 4)->second == 1.5);
135         assert(next(m.begin(), 5)->first == 3);
136         assert(next(m.begin(), 5)->second == 2);
137 
138         i = m.erase(3);
139         assert(i == 3);
140         assert(m.size() == 3);
141         assert(next(m.begin(), 0)->first == 1);
142         assert(next(m.begin(), 0)->second == 1);
143         assert(next(m.begin(), 1)->first == 1);
144         assert(next(m.begin(), 1)->second == 1.5);
145         assert(next(m.begin(), 2)->first == 1);
146         assert(next(m.begin(), 2)->second == 2);
147 
148         i = m.erase(1);
149         assert(m.size() == 0);
150         assert(i == 3);
151     }
152 #endif
153 }
154