Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / containers / associative / multiset / erase_iter_iter.pass.cpp
blob54f694926f05e35e006bd6247b138192098dce0a
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 first, const_iterator last);
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::iterator I;
27 V ar[] =
38 M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
39 assert(m.size() == 8);
40 I i = m.erase(std::next(m.cbegin(), 5), std::next(m.cbegin(), 5));
41 assert(m.size() == 8);
42 assert(i == std::next(m.begin(), 5));
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(std::next(m.cbegin(), 3), std::next(m.cbegin(), 4));
53 assert(m.size() == 7);
54 assert(i == std::next(m.begin(), 3));
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(std::next(m.cbegin(), 2), std::next(m.cbegin(), 5));
64 assert(m.size() == 4);
65 assert(i == std::next(m.begin(), 2));
66 assert(*std::next(m.begin(), 0) == 1);
67 assert(*std::next(m.begin(), 1) == 2);
68 assert(*std::next(m.begin(), 2) == 7);
69 assert(*std::next(m.begin(), 3) == 8);
71 i = m.erase(std::next(m.cbegin(), 0), std::next(m.cbegin(), 2));
72 assert(m.size() == 2);
73 assert(i == std::next(m.begin(), 0));
74 assert(*std::next(m.begin(), 0) == 7);
75 assert(*std::next(m.begin(), 1) == 8);
77 i = m.erase(m.cbegin(), m.cend());
78 assert(m.size() == 0);
79 assert(i == m.end());
81 #if TEST_STD_VER >= 11
83 typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
84 typedef int V;
85 typedef M::iterator I;
86 V ar[] =
97 M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
98 assert(m.size() == 8);
99 I i = m.erase(std::next(m.cbegin(), 5), std::next(m.cbegin(), 5));
100 assert(m.size() == 8);
101 assert(i == std::next(m.begin(), 5));
102 assert(*std::next(m.begin(), 0) == 1);
103 assert(*std::next(m.begin(), 1) == 2);
104 assert(*std::next(m.begin(), 2) == 3);
105 assert(*std::next(m.begin(), 3) == 4);
106 assert(*std::next(m.begin(), 4) == 5);
107 assert(*std::next(m.begin(), 5) == 6);
108 assert(*std::next(m.begin(), 6) == 7);
109 assert(*std::next(m.begin(), 7) == 8);
111 i = m.erase(std::next(m.cbegin(), 3), std::next(m.cbegin(), 4));
112 assert(m.size() == 7);
113 assert(i == std::next(m.begin(), 3));
114 assert(*std::next(m.begin(), 0) == 1);
115 assert(*std::next(m.begin(), 1) == 2);
116 assert(*std::next(m.begin(), 2) == 3);
117 assert(*std::next(m.begin(), 3) == 5);
118 assert(*std::next(m.begin(), 4) == 6);
119 assert(*std::next(m.begin(), 5) == 7);
120 assert(*std::next(m.begin(), 6) == 8);
122 i = m.erase(std::next(m.cbegin(), 2), std::next(m.cbegin(), 5));
123 assert(m.size() == 4);
124 assert(i == std::next(m.begin(), 2));
125 assert(*std::next(m.begin(), 0) == 1);
126 assert(*std::next(m.begin(), 1) == 2);
127 assert(*std::next(m.begin(), 2) == 7);
128 assert(*std::next(m.begin(), 3) == 8);
130 i = m.erase(std::next(m.cbegin(), 0), std::next(m.cbegin(), 2));
131 assert(m.size() == 2);
132 assert(i == std::next(m.begin(), 0));
133 assert(*std::next(m.begin(), 0) == 7);
134 assert(*std::next(m.begin(), 1) == 8);
136 i = m.erase(m.cbegin(), m.cend());
137 assert(m.size() == 0);
138 assert(i == m.end());
140 #endif
142 return 0;