• 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 // <map>
11 
12 // class multimap
13 
14 // size_type erase(const key_type& k);
15 
16 #include <map>
17 #include <cassert>
18 
main()19 int main()
20 {
21     {
22         typedef std::multimap<int, double> M;
23         typedef std::pair<int, double> P;
24         typedef M::size_type I;
25         P ar[] =
26         {
27             P(1, 1),
28             P(1, 1.5),
29             P(1, 2),
30             P(2, 1),
31             P(2, 1.5),
32             P(2, 2),
33             P(3, 1),
34             P(3, 1.5),
35             P(3, 2),
36         };
37         M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
38         assert(m.size() == 9);
39         I i = m.erase(2);
40         assert(m.size() == 6);
41         assert(i == 3);
42         assert(next(m.begin(), 0)->first == 1);
43         assert(next(m.begin(), 0)->second == 1);
44         assert(next(m.begin(), 1)->first == 1);
45         assert(next(m.begin(), 1)->second == 1.5);
46         assert(next(m.begin(), 2)->first == 1);
47         assert(next(m.begin(), 2)->second == 2);
48         assert(next(m.begin(), 3)->first == 3);
49         assert(next(m.begin(), 3)->second == 1);
50         assert(next(m.begin(), 4)->first == 3);
51         assert(next(m.begin(), 4)->second == 1.5);
52         assert(next(m.begin(), 5)->first == 3);
53         assert(next(m.begin(), 5)->second == 2);
54 
55         i = m.erase(2);
56         assert(m.size() == 6);
57         assert(i == 0);
58         assert(next(m.begin(), 0)->first == 1);
59         assert(next(m.begin(), 0)->second == 1);
60         assert(next(m.begin(), 1)->first == 1);
61         assert(next(m.begin(), 1)->second == 1.5);
62         assert(next(m.begin(), 2)->first == 1);
63         assert(next(m.begin(), 2)->second == 2);
64         assert(next(m.begin(), 3)->first == 3);
65         assert(next(m.begin(), 3)->second == 1);
66         assert(next(m.begin(), 4)->first == 3);
67         assert(next(m.begin(), 4)->second == 1.5);
68         assert(next(m.begin(), 5)->first == 3);
69         assert(next(m.begin(), 5)->second == 2);
70 
71         i = m.erase(3);
72         assert(m.size() == 3);
73         assert(next(m.begin(), 0)->first == 1);
74         assert(next(m.begin(), 0)->second == 1);
75         assert(next(m.begin(), 1)->first == 1);
76         assert(next(m.begin(), 1)->second == 1.5);
77         assert(next(m.begin(), 2)->first == 1);
78         assert(next(m.begin(), 2)->second == 2);
79 
80         i = m.erase(1);
81         assert(m.size() == 0);
82         assert(i == 3);
83     }
84 }
85