Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / containers / associative / multiset / erase_key.pass.cpp
blobfa5c9d646a65237f819c1160f2e528345ed61435
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 // 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::multiset<int> M;
25 typedef int V;
26 typedef M::size_type I;
27 V ar[] =
39 M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
40 assert(m.size() == 9);
41 I i = m.erase(6);
42 assert(m.size() == 9);
43 assert(i == 0);
44 assert(*std::next(m.begin(), 0) == 3);
45 assert(*std::next(m.begin(), 1) == 3);
46 assert(*std::next(m.begin(), 2) == 3);
47 assert(*std::next(m.begin(), 3) == 5);
48 assert(*std::next(m.begin(), 4) == 5);
49 assert(*std::next(m.begin(), 5) == 5);
50 assert(*std::next(m.begin(), 6) == 7);
51 assert(*std::next(m.begin(), 7) == 7);
52 assert(*std::next(m.begin(), 8) == 7);
54 i = m.erase(5);
55 assert(m.size() == 6);
56 assert(i == 3);
57 assert(*std::next(m.begin(), 0) == 3);
58 assert(*std::next(m.begin(), 1) == 3);
59 assert(*std::next(m.begin(), 2) == 3);
60 assert(*std::next(m.begin(), 3) == 7);
61 assert(*std::next(m.begin(), 4) == 7);
62 assert(*std::next(m.begin(), 5) == 7);
64 i = m.erase(3);
65 assert(m.size() == 3);
66 assert(i == 3);
67 assert(*std::next(m.begin(), 0) == 7);
68 assert(*std::next(m.begin(), 1) == 7);
69 assert(*std::next(m.begin(), 2) == 7);
71 i = m.erase(7);
72 assert(m.size() == 0);
73 assert(i == 3);
75 #if TEST_STD_VER >= 11
77 typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
78 typedef int V;
79 typedef M::size_type I;
80 V ar[] =
92 M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
93 assert(m.size() == 9);
94 I i = m.erase(6);
95 assert(m.size() == 9);
96 assert(i == 0);
97 assert(*std::next(m.begin(), 0) == 3);
98 assert(*std::next(m.begin(), 1) == 3);
99 assert(*std::next(m.begin(), 2) == 3);
100 assert(*std::next(m.begin(), 3) == 5);
101 assert(*std::next(m.begin(), 4) == 5);
102 assert(*std::next(m.begin(), 5) == 5);
103 assert(*std::next(m.begin(), 6) == 7);
104 assert(*std::next(m.begin(), 7) == 7);
105 assert(*std::next(m.begin(), 8) == 7);
107 i = m.erase(5);
108 assert(m.size() == 6);
109 assert(i == 3);
110 assert(*std::next(m.begin(), 0) == 3);
111 assert(*std::next(m.begin(), 1) == 3);
112 assert(*std::next(m.begin(), 2) == 3);
113 assert(*std::next(m.begin(), 3) == 7);
114 assert(*std::next(m.begin(), 4) == 7);
115 assert(*std::next(m.begin(), 5) == 7);
117 i = m.erase(3);
118 assert(m.size() == 3);
119 assert(i == 3);
120 assert(*std::next(m.begin(), 0) == 7);
121 assert(*std::next(m.begin(), 1) == 7);
122 assert(*std::next(m.begin(), 2) == 7);
124 i = m.erase(7);
125 assert(m.size() == 0);
126 assert(i == 3);
128 #endif
130 return 0;