Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / containers / associative / multimap / multimap.modifiers / erase_key.pass.cpp
blobf00436db264c95b7078a38dc9222a617132b8f1e
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <map>
11 // class multimap
13 // size_type erase(const key_type& k);
15 #include <map>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "min_allocator.h"
21 int main(int, char**)
24 typedef std::multimap<int, double> M;
25 typedef std::pair<int, double> P;
26 typedef M::size_type I;
27 P ar[] =
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),
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(std::next(m.begin(), 0)->first == 1);
45 assert(std::next(m.begin(), 0)->second == 1);
46 assert(std::next(m.begin(), 1)->first == 1);
47 assert(std::next(m.begin(), 1)->second == 1.5);
48 assert(std::next(m.begin(), 2)->first == 1);
49 assert(std::next(m.begin(), 2)->second == 2);
50 assert(std::next(m.begin(), 3)->first == 3);
51 assert(std::next(m.begin(), 3)->second == 1);
52 assert(std::next(m.begin(), 4)->first == 3);
53 assert(std::next(m.begin(), 4)->second == 1.5);
54 assert(std::next(m.begin(), 5)->first == 3);
55 assert(std::next(m.begin(), 5)->second == 2);
57 i = m.erase(2);
58 assert(m.size() == 6);
59 assert(i == 0);
60 assert(std::next(m.begin(), 0)->first == 1);
61 assert(std::next(m.begin(), 0)->second == 1);
62 assert(std::next(m.begin(), 1)->first == 1);
63 assert(std::next(m.begin(), 1)->second == 1.5);
64 assert(std::next(m.begin(), 2)->first == 1);
65 assert(std::next(m.begin(), 2)->second == 2);
66 assert(std::next(m.begin(), 3)->first == 3);
67 assert(std::next(m.begin(), 3)->second == 1);
68 assert(std::next(m.begin(), 4)->first == 3);
69 assert(std::next(m.begin(), 4)->second == 1.5);
70 assert(std::next(m.begin(), 5)->first == 3);
71 assert(std::next(m.begin(), 5)->second == 2);
73 i = m.erase(3);
74 assert(i == 3);
75 assert(m.size() == 3);
76 assert(std::next(m.begin(), 0)->first == 1);
77 assert(std::next(m.begin(), 0)->second == 1);
78 assert(std::next(m.begin(), 1)->first == 1);
79 assert(std::next(m.begin(), 1)->second == 1.5);
80 assert(std::next(m.begin(), 2)->first == 1);
81 assert(std::next(m.begin(), 2)->second == 2);
83 i = m.erase(1);
84 assert(m.size() == 0);
85 assert(i == 3);
87 #if TEST_STD_VER >= 11
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[] =
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),
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(std::next(m.begin(), 0)->first == 1);
110 assert(std::next(m.begin(), 0)->second == 1);
111 assert(std::next(m.begin(), 1)->first == 1);
112 assert(std::next(m.begin(), 1)->second == 1.5);
113 assert(std::next(m.begin(), 2)->first == 1);
114 assert(std::next(m.begin(), 2)->second == 2);
115 assert(std::next(m.begin(), 3)->first == 3);
116 assert(std::next(m.begin(), 3)->second == 1);
117 assert(std::next(m.begin(), 4)->first == 3);
118 assert(std::next(m.begin(), 4)->second == 1.5);
119 assert(std::next(m.begin(), 5)->first == 3);
120 assert(std::next(m.begin(), 5)->second == 2);
122 i = m.erase(2);
123 assert(m.size() == 6);
124 assert(i == 0);
125 assert(std::next(m.begin(), 0)->first == 1);
126 assert(std::next(m.begin(), 0)->second == 1);
127 assert(std::next(m.begin(), 1)->first == 1);
128 assert(std::next(m.begin(), 1)->second == 1.5);
129 assert(std::next(m.begin(), 2)->first == 1);
130 assert(std::next(m.begin(), 2)->second == 2);
131 assert(std::next(m.begin(), 3)->first == 3);
132 assert(std::next(m.begin(), 3)->second == 1);
133 assert(std::next(m.begin(), 4)->first == 3);
134 assert(std::next(m.begin(), 4)->second == 1.5);
135 assert(std::next(m.begin(), 5)->first == 3);
136 assert(std::next(m.begin(), 5)->second == 2);
138 i = m.erase(3);
139 assert(i == 3);
140 assert(m.size() == 3);
141 assert(std::next(m.begin(), 0)->first == 1);
142 assert(std::next(m.begin(), 0)->second == 1);
143 assert(std::next(m.begin(), 1)->first == 1);
144 assert(std::next(m.begin(), 1)->second == 1.5);
145 assert(std::next(m.begin(), 2)->first == 1);
146 assert(std::next(m.begin(), 2)->second == 2);
148 i = m.erase(1);
149 assert(m.size() == 0);
150 assert(i == 3);
152 #endif
154 return 0;