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