• 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 // <set>
11 
12 // class multiset
13 
14 // iterator erase(const_iterator position);
15 
16 #include <set>
17 #include <cassert>
18 
main()19 int main()
20 {
21     {
22         typedef std::multiset<int> M;
23         typedef int V;
24         typedef M::iterator I;
25         V ar[] =
26         {
27             1,
28             2,
29             3,
30             4,
31             5,
32             6,
33             7,
34             8
35         };
36         M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
37         assert(m.size() == 8);
38         I i = m.erase(next(m.cbegin(), 3));
39         assert(m.size() == 7);
40         assert(i == next(m.begin(), 3));
41         assert(*next(m.begin(), 0) == 1);
42         assert(*next(m.begin(), 1) == 2);
43         assert(*next(m.begin(), 2) == 3);
44         assert(*next(m.begin(), 3) == 5);
45         assert(*next(m.begin(), 4) == 6);
46         assert(*next(m.begin(), 5) == 7);
47         assert(*next(m.begin(), 6) == 8);
48 
49         i = m.erase(next(m.cbegin(), 0));
50         assert(m.size() == 6);
51         assert(i == m.begin());
52         assert(*next(m.begin(), 0) == 2);
53         assert(*next(m.begin(), 1) == 3);
54         assert(*next(m.begin(), 2) == 5);
55         assert(*next(m.begin(), 3) == 6);
56         assert(*next(m.begin(), 4) == 7);
57         assert(*next(m.begin(), 5) == 8);
58 
59         i = m.erase(next(m.cbegin(), 5));
60         assert(m.size() == 5);
61         assert(i == m.end());
62         assert(*next(m.begin(), 0) == 2);
63         assert(*next(m.begin(), 1) == 3);
64         assert(*next(m.begin(), 2) == 5);
65         assert(*next(m.begin(), 3) == 6);
66         assert(*next(m.begin(), 4) == 7);
67 
68         i = m.erase(next(m.cbegin(), 1));
69         assert(m.size() == 4);
70         assert(i == next(m.begin()));
71         assert(*next(m.begin(), 0) == 2);
72         assert(*next(m.begin(), 1) == 5);
73         assert(*next(m.begin(), 2) == 6);
74         assert(*next(m.begin(), 3) == 7);
75 
76         i = m.erase(next(m.cbegin(), 2));
77         assert(m.size() == 3);
78         assert(i == next(m.begin(), 2));
79         assert(*next(m.begin(), 0) == 2);
80         assert(*next(m.begin(), 1) == 5);
81         assert(*next(m.begin(), 2) == 7);
82 
83         i = m.erase(next(m.cbegin(), 2));
84         assert(m.size() == 2);
85         assert(i == next(m.begin(), 2));
86         assert(*next(m.begin(), 0) == 2);
87         assert(*next(m.begin(), 1) == 5);
88 
89         i = m.erase(next(m.cbegin(), 0));
90         assert(m.size() == 1);
91         assert(i == next(m.begin(), 0));
92         assert(*next(m.begin(), 0) == 5);
93 
94         i = m.erase(m.cbegin());
95         assert(m.size() == 0);
96         assert(i == m.begin());
97         assert(i == m.end());
98     }
99 }
100