[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / containers / associative / set / erase_key.pass.cpp
blob03b78eb12312f71fad8a3c04d26915b6794efa60
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 // <set>
11 // class set
13 // size_type erase(const key_type& k);
15 #include <set>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "min_allocator.h"
21 int main(int, char**)
24 typedef std::set<int> M;
25 typedef int V;
26 typedef M::size_type I;
27 V ar[] =
38 M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
39 assert(m.size() == 8);
40 I i = m.erase(9);
41 assert(m.size() == 8);
42 assert(i == 0);
43 assert(*std::next(m.begin(), 0) == 1);
44 assert(*std::next(m.begin(), 1) == 2);
45 assert(*std::next(m.begin(), 2) == 3);
46 assert(*std::next(m.begin(), 3) == 4);
47 assert(*std::next(m.begin(), 4) == 5);
48 assert(*std::next(m.begin(), 5) == 6);
49 assert(*std::next(m.begin(), 6) == 7);
50 assert(*std::next(m.begin(), 7) == 8);
52 i = m.erase(4);
53 assert(m.size() == 7);
54 assert(i == 1);
55 assert(*std::next(m.begin(), 0) == 1);
56 assert(*std::next(m.begin(), 1) == 2);
57 assert(*std::next(m.begin(), 2) == 3);
58 assert(*std::next(m.begin(), 3) == 5);
59 assert(*std::next(m.begin(), 4) == 6);
60 assert(*std::next(m.begin(), 5) == 7);
61 assert(*std::next(m.begin(), 6) == 8);
63 i = m.erase(1);
64 assert(m.size() == 6);
65 assert(i == 1);
66 assert(*std::next(m.begin(), 0) == 2);
67 assert(*std::next(m.begin(), 1) == 3);
68 assert(*std::next(m.begin(), 2) == 5);
69 assert(*std::next(m.begin(), 3) == 6);
70 assert(*std::next(m.begin(), 4) == 7);
71 assert(*std::next(m.begin(), 5) == 8);
73 i = m.erase(8);
74 assert(m.size() == 5);
75 assert(i == 1);
76 assert(*std::next(m.begin(), 0) == 2);
77 assert(*std::next(m.begin(), 1) == 3);
78 assert(*std::next(m.begin(), 2) == 5);
79 assert(*std::next(m.begin(), 3) == 6);
80 assert(*std::next(m.begin(), 4) == 7);
82 i = m.erase(3);
83 assert(m.size() == 4);
84 assert(i == 1);
85 assert(*std::next(m.begin(), 0) == 2);
86 assert(*std::next(m.begin(), 1) == 5);
87 assert(*std::next(m.begin(), 2) == 6);
88 assert(*std::next(m.begin(), 3) == 7);
90 i = m.erase(6);
91 assert(m.size() == 3);
92 assert(i == 1);
93 assert(*std::next(m.begin(), 0) == 2);
94 assert(*std::next(m.begin(), 1) == 5);
95 assert(*std::next(m.begin(), 2) == 7);
97 i = m.erase(7);
98 assert(m.size() == 2);
99 assert(i == 1);
100 assert(*std::next(m.begin(), 0) == 2);
101 assert(*std::next(m.begin(), 1) == 5);
103 i = m.erase(2);
104 assert(m.size() == 1);
105 assert(i == 1);
106 assert(*std::next(m.begin(), 0) == 5);
108 i = m.erase(5);
109 assert(m.size() == 0);
110 assert(i == 1);
112 #if TEST_STD_VER >= 11
114 typedef std::set<int, std::less<int>, min_allocator<int>> M;
115 typedef int V;
116 typedef M::size_type I;
117 V ar[] =
128 M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
129 assert(m.size() == 8);
130 I i = m.erase(9);
131 assert(m.size() == 8);
132 assert(i == 0);
133 assert(*std::next(m.begin(), 0) == 1);
134 assert(*std::next(m.begin(), 1) == 2);
135 assert(*std::next(m.begin(), 2) == 3);
136 assert(*std::next(m.begin(), 3) == 4);
137 assert(*std::next(m.begin(), 4) == 5);
138 assert(*std::next(m.begin(), 5) == 6);
139 assert(*std::next(m.begin(), 6) == 7);
140 assert(*std::next(m.begin(), 7) == 8);
142 i = m.erase(4);
143 assert(m.size() == 7);
144 assert(i == 1);
145 assert(*std::next(m.begin(), 0) == 1);
146 assert(*std::next(m.begin(), 1) == 2);
147 assert(*std::next(m.begin(), 2) == 3);
148 assert(*std::next(m.begin(), 3) == 5);
149 assert(*std::next(m.begin(), 4) == 6);
150 assert(*std::next(m.begin(), 5) == 7);
151 assert(*std::next(m.begin(), 6) == 8);
153 i = m.erase(1);
154 assert(m.size() == 6);
155 assert(i == 1);
156 assert(*std::next(m.begin(), 0) == 2);
157 assert(*std::next(m.begin(), 1) == 3);
158 assert(*std::next(m.begin(), 2) == 5);
159 assert(*std::next(m.begin(), 3) == 6);
160 assert(*std::next(m.begin(), 4) == 7);
161 assert(*std::next(m.begin(), 5) == 8);
163 i = m.erase(8);
164 assert(m.size() == 5);
165 assert(i == 1);
166 assert(*std::next(m.begin(), 0) == 2);
167 assert(*std::next(m.begin(), 1) == 3);
168 assert(*std::next(m.begin(), 2) == 5);
169 assert(*std::next(m.begin(), 3) == 6);
170 assert(*std::next(m.begin(), 4) == 7);
172 i = m.erase(3);
173 assert(m.size() == 4);
174 assert(i == 1);
175 assert(*std::next(m.begin(), 0) == 2);
176 assert(*std::next(m.begin(), 1) == 5);
177 assert(*std::next(m.begin(), 2) == 6);
178 assert(*std::next(m.begin(), 3) == 7);
180 i = m.erase(6);
181 assert(m.size() == 3);
182 assert(i == 1);
183 assert(*std::next(m.begin(), 0) == 2);
184 assert(*std::next(m.begin(), 1) == 5);
185 assert(*std::next(m.begin(), 2) == 7);
187 i = m.erase(7);
188 assert(m.size() == 2);
189 assert(i == 1);
190 assert(*std::next(m.begin(), 0) == 2);
191 assert(*std::next(m.begin(), 1) == 5);
193 i = m.erase(2);
194 assert(m.size() == 1);
195 assert(i == 1);
196 assert(*std::next(m.begin(), 0) == 5);
198 i = m.erase(5);
199 assert(m.size() == 0);
200 assert(i == 1);
202 #endif
204 return 0;