Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / containers / unord / unord.multiset / erase_const_iter.pass.cpp
blobffdcde80d14d3cf43397e11d188934c1827422d3
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 // <unordered_set>
11 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
12 // class Alloc = allocator<Value>>
13 // class unordered_multiset
15 // iterator erase(const_iterator p)
17 #include <unordered_set>
18 #include <cassert>
20 #include "test_macros.h"
21 #include "min_allocator.h"
23 struct TemplateConstructor
25 template<typename T>
26 TemplateConstructor (const T&) {}
29 bool operator==(const TemplateConstructor&, const TemplateConstructor&) { return false; }
30 struct Hash { std::size_t operator() (const TemplateConstructor &) const { return 0; } };
32 int main(int, char**)
35 typedef std::unordered_multiset<int> C;
36 typedef int P;
37 P a[] =
39 P(1),
40 P(2),
41 P(3),
42 P(4),
43 P(1),
44 P(2)
46 C c(a, a + sizeof(a)/sizeof(a[0]));
47 C::const_iterator i = c.find(2);
48 C::const_iterator i_next = i;
49 ++i_next;
50 C::iterator j = c.erase(i);
51 assert(j == i_next);
53 assert(c.size() == 5);
54 assert(c.count(1) == 2);
55 assert(c.count(2) == 1);
56 assert(c.count(3) == 1);
57 assert(c.count(4) == 1);
59 #if TEST_STD_VER >= 11
61 typedef std::unordered_multiset<int, std::hash<int>,
62 std::equal_to<int>, min_allocator<int>> C;
63 typedef int P;
64 P a[] =
66 P(1),
67 P(2),
68 P(3),
69 P(4),
70 P(1),
71 P(2)
73 C c(a, a + sizeof(a)/sizeof(a[0]));
74 C::const_iterator i = c.find(2);
75 C::const_iterator i_next = i;
76 ++i_next;
77 C::iterator j = c.erase(i);
78 assert(j == i_next);
79 assert(c.size() == 5);
80 assert(c.count(1) == 2);
81 assert(c.count(2) == 1);
82 assert(c.count(3) == 1);
83 assert(c.count(4) == 1);
85 #endif
86 #if TEST_STD_VER >= 14
88 // This is LWG #2059
89 typedef TemplateConstructor T;
90 typedef std::unordered_set<T, Hash> C;
91 typedef C::iterator I;
93 C m;
94 T a{0};
95 I it = m.find(a);
96 if (it != m.end())
97 m.erase(it);
99 #endif
101 return 0;