[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / containers / associative / multiset / erase_iter.pass.cpp
bloba42d48b7847df9530d92de6a35d2181fc51c58c5
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 multiset
13 // iterator erase(const_iterator position);
15 #include <set>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "min_allocator.h"
21 struct TemplateConstructor
23 template<typename T>
24 TemplateConstructor (const T&) {}
27 bool operator<(const TemplateConstructor&, const TemplateConstructor&) { return false; }
29 int main(int, char**)
32 typedef std::multiset<int> M;
33 typedef int V;
34 typedef M::iterator I;
35 V ar[] =
46 M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
47 assert(m.size() == 8);
48 I i = m.erase(std::next(m.cbegin(), 3));
49 assert(m.size() == 7);
50 assert(i == std::next(m.begin(), 3));
51 assert(*std::next(m.begin(), 0) == 1);
52 assert(*std::next(m.begin(), 1) == 2);
53 assert(*std::next(m.begin(), 2) == 3);
54 assert(*std::next(m.begin(), 3) == 5);
55 assert(*std::next(m.begin(), 4) == 6);
56 assert(*std::next(m.begin(), 5) == 7);
57 assert(*std::next(m.begin(), 6) == 8);
59 i = m.erase(std::next(m.cbegin(), 0));
60 assert(m.size() == 6);
61 assert(i == m.begin());
62 assert(*std::next(m.begin(), 0) == 2);
63 assert(*std::next(m.begin(), 1) == 3);
64 assert(*std::next(m.begin(), 2) == 5);
65 assert(*std::next(m.begin(), 3) == 6);
66 assert(*std::next(m.begin(), 4) == 7);
67 assert(*std::next(m.begin(), 5) == 8);
69 i = m.erase(std::next(m.cbegin(), 5));
70 assert(m.size() == 5);
71 assert(i == m.end());
72 assert(*std::next(m.begin(), 0) == 2);
73 assert(*std::next(m.begin(), 1) == 3);
74 assert(*std::next(m.begin(), 2) == 5);
75 assert(*std::next(m.begin(), 3) == 6);
76 assert(*std::next(m.begin(), 4) == 7);
78 i = m.erase(std::next(m.cbegin(), 1));
79 assert(m.size() == 4);
80 assert(i == std::next(m.begin()));
81 assert(*std::next(m.begin(), 0) == 2);
82 assert(*std::next(m.begin(), 1) == 5);
83 assert(*std::next(m.begin(), 2) == 6);
84 assert(*std::next(m.begin(), 3) == 7);
86 i = m.erase(std::next(m.cbegin(), 2));
87 assert(m.size() == 3);
88 assert(i == std::next(m.begin(), 2));
89 assert(*std::next(m.begin(), 0) == 2);
90 assert(*std::next(m.begin(), 1) == 5);
91 assert(*std::next(m.begin(), 2) == 7);
93 i = m.erase(std::next(m.cbegin(), 2));
94 assert(m.size() == 2);
95 assert(i == std::next(m.begin(), 2));
96 assert(*std::next(m.begin(), 0) == 2);
97 assert(*std::next(m.begin(), 1) == 5);
99 i = m.erase(std::next(m.cbegin(), 0));
100 assert(m.size() == 1);
101 assert(i == std::next(m.begin(), 0));
102 assert(*std::next(m.begin(), 0) == 5);
104 i = m.erase(m.cbegin());
105 assert(m.size() == 0);
106 assert(i == m.begin());
107 assert(i == m.end());
109 #if TEST_STD_VER >= 11
111 typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
112 typedef int V;
113 typedef M::iterator I;
114 V ar[] =
125 M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
126 assert(m.size() == 8);
127 I i = m.erase(std::next(m.cbegin(), 3));
128 assert(m.size() == 7);
129 assert(i == std::next(m.begin(), 3));
130 assert(*std::next(m.begin(), 0) == 1);
131 assert(*std::next(m.begin(), 1) == 2);
132 assert(*std::next(m.begin(), 2) == 3);
133 assert(*std::next(m.begin(), 3) == 5);
134 assert(*std::next(m.begin(), 4) == 6);
135 assert(*std::next(m.begin(), 5) == 7);
136 assert(*std::next(m.begin(), 6) == 8);
138 i = m.erase(std::next(m.cbegin(), 0));
139 assert(m.size() == 6);
140 assert(i == m.begin());
141 assert(*std::next(m.begin(), 0) == 2);
142 assert(*std::next(m.begin(), 1) == 3);
143 assert(*std::next(m.begin(), 2) == 5);
144 assert(*std::next(m.begin(), 3) == 6);
145 assert(*std::next(m.begin(), 4) == 7);
146 assert(*std::next(m.begin(), 5) == 8);
148 i = m.erase(std::next(m.cbegin(), 5));
149 assert(m.size() == 5);
150 assert(i == m.end());
151 assert(*std::next(m.begin(), 0) == 2);
152 assert(*std::next(m.begin(), 1) == 3);
153 assert(*std::next(m.begin(), 2) == 5);
154 assert(*std::next(m.begin(), 3) == 6);
155 assert(*std::next(m.begin(), 4) == 7);
157 i = m.erase(std::next(m.cbegin(), 1));
158 assert(m.size() == 4);
159 assert(i == std::next(m.begin()));
160 assert(*std::next(m.begin(), 0) == 2);
161 assert(*std::next(m.begin(), 1) == 5);
162 assert(*std::next(m.begin(), 2) == 6);
163 assert(*std::next(m.begin(), 3) == 7);
165 i = m.erase(std::next(m.cbegin(), 2));
166 assert(m.size() == 3);
167 assert(i == std::next(m.begin(), 2));
168 assert(*std::next(m.begin(), 0) == 2);
169 assert(*std::next(m.begin(), 1) == 5);
170 assert(*std::next(m.begin(), 2) == 7);
172 i = m.erase(std::next(m.cbegin(), 2));
173 assert(m.size() == 2);
174 assert(i == std::next(m.begin(), 2));
175 assert(*std::next(m.begin(), 0) == 2);
176 assert(*std::next(m.begin(), 1) == 5);
178 i = m.erase(std::next(m.cbegin(), 0));
179 assert(m.size() == 1);
180 assert(i == std::next(m.begin(), 0));
181 assert(*std::next(m.begin(), 0) == 5);
183 i = m.erase(m.cbegin());
184 assert(m.size() == 0);
185 assert(i == m.begin());
186 assert(i == m.end());
188 #endif
189 #if TEST_STD_VER >= 14
191 // This is LWG #2059
192 typedef TemplateConstructor T;
193 typedef std::multiset<T> C;
194 typedef C::iterator I;
196 C c;
197 T a{0};
198 I it = c.find(a);
199 if (it != c.end())
200 c.erase(it);
202 #endif
204 return 0;