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 // size_type erase(const key_type& k);
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::size_type I;
27 V ar[] =
28 {
29 3,
30 3,
31 3,
32 5,
33 5,
34 5,
35 7,
36 7,
37 7
38 };
39 M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
40 assert(m.size() == 9);
41 I i = m.erase(6);
42 assert(m.size() == 9);
43 assert(i == 0);
44 assert(*next(m.begin(), 0) == 3);
45 assert(*next(m.begin(), 1) == 3);
46 assert(*next(m.begin(), 2) == 3);
47 assert(*next(m.begin(), 3) == 5);
48 assert(*next(m.begin(), 4) == 5);
49 assert(*next(m.begin(), 5) == 5);
50 assert(*next(m.begin(), 6) == 7);
51 assert(*next(m.begin(), 7) == 7);
52 assert(*next(m.begin(), 8) == 7);
53
54 i = m.erase(5);
55 assert(m.size() == 6);
56 assert(i == 3);
57 assert(*next(m.begin(), 0) == 3);
58 assert(*next(m.begin(), 1) == 3);
59 assert(*next(m.begin(), 2) == 3);
60 assert(*next(m.begin(), 3) == 7);
61 assert(*next(m.begin(), 4) == 7);
62 assert(*next(m.begin(), 5) == 7);
63
64 i = m.erase(3);
65 assert(m.size() == 3);
66 assert(i == 3);
67 assert(*next(m.begin(), 0) == 7);
68 assert(*next(m.begin(), 1) == 7);
69 assert(*next(m.begin(), 2) == 7);
70
71 i = m.erase(7);
72 assert(m.size() == 0);
73 assert(i == 3);
74 }
75 #if __cplusplus >= 201103L
76 {
77 typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
78 typedef int V;
79 typedef M::size_type I;
80 V ar[] =
81 {
82 3,
83 3,
84 3,
85 5,
86 5,
87 5,
88 7,
89 7,
90 7
91 };
92 M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
93 assert(m.size() == 9);
94 I i = m.erase(6);
95 assert(m.size() == 9);
96 assert(i == 0);
97 assert(*next(m.begin(), 0) == 3);
98 assert(*next(m.begin(), 1) == 3);
99 assert(*next(m.begin(), 2) == 3);
100 assert(*next(m.begin(), 3) == 5);
101 assert(*next(m.begin(), 4) == 5);
102 assert(*next(m.begin(), 5) == 5);
103 assert(*next(m.begin(), 6) == 7);
104 assert(*next(m.begin(), 7) == 7);
105 assert(*next(m.begin(), 8) == 7);
106
107 i = m.erase(5);
108 assert(m.size() == 6);
109 assert(i == 3);
110 assert(*next(m.begin(), 0) == 3);
111 assert(*next(m.begin(), 1) == 3);
112 assert(*next(m.begin(), 2) == 3);
113 assert(*next(m.begin(), 3) == 7);
114 assert(*next(m.begin(), 4) == 7);
115 assert(*next(m.begin(), 5) == 7);
116
117 i = m.erase(3);
118 assert(m.size() == 3);
119 assert(i == 3);
120 assert(*next(m.begin(), 0) == 7);
121 assert(*next(m.begin(), 1) == 7);
122 assert(*next(m.begin(), 2) == 7);
123
124 i = m.erase(7);
125 assert(m.size() == 0);
126 assert(i == 3);
127 }
128 #endif
129 }
130