1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
12 // class Alloc = allocator<Value>>
13 // class unordered_set
15 // size_type erase(const key_type& k);
17 #include <unordered_set>
21 #include "test_macros.h"
22 #include "min_allocator.h"
24 #if TEST_STD_VER >= 11
25 template <typename Unordered
>
26 bool only_deletions ( const Unordered
&whole
, const Unordered
&part
) {
27 typename
Unordered::const_iterator w
= whole
.begin();
28 typename
Unordered::const_iterator p
= part
.begin();
30 while ( w
!= whole
.end () && p
!= part
.end()) {
36 return p
== part
.end();
43 typedef std::unordered_set
<int> C
;
54 C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
55 assert(c
.erase(5) == 0);
56 assert(c
.size() == 4);
57 assert(c
.count(1) == 1);
58 assert(c
.count(2) == 1);
59 assert(c
.count(3) == 1);
60 assert(c
.count(4) == 1);
62 assert(c
.erase(2) == 1);
63 assert(c
.size() == 3);
64 assert(c
.count(1) == 1);
65 assert(c
.count(3) == 1);
66 assert(c
.count(4) == 1);
68 assert(c
.erase(2) == 0);
69 assert(c
.size() == 3);
70 assert(c
.count(1) == 1);
71 assert(c
.count(3) == 1);
72 assert(c
.count(4) == 1);
74 assert(c
.erase(4) == 1);
75 assert(c
.size() == 2);
76 assert(c
.count(1) == 1);
77 assert(c
.count(3) == 1);
79 assert(c
.erase(4) == 0);
80 assert(c
.size() == 2);
81 assert(c
.count(1) == 1);
82 assert(c
.count(3) == 1);
84 assert(c
.erase(1) == 1);
85 assert(c
.size() == 1);
86 assert(c
.count(3) == 1);
88 assert(c
.erase(1) == 0);
89 assert(c
.size() == 1);
90 assert(c
.count(3) == 1);
92 assert(c
.erase(3) == 1);
93 assert(c
.size() == 0);
95 assert(c
.erase(3) == 0);
96 assert(c
.size() == 0);
98 #if TEST_STD_VER >= 11
100 typedef std::unordered_set
<int, std::hash
<int>, std::equal_to
<int>, min_allocator
<int>> C
;
111 C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
112 assert(c
.erase(5) == 0);
113 assert(c
.size() == 4);
114 assert(c
.count(1) == 1);
115 assert(c
.count(2) == 1);
116 assert(c
.count(3) == 1);
117 assert(c
.count(4) == 1);
119 assert(c
.erase(2) == 1);
120 assert(c
.size() == 3);
121 assert(c
.count(1) == 1);
122 assert(c
.count(3) == 1);
123 assert(c
.count(4) == 1);
125 assert(c
.erase(2) == 0);
126 assert(c
.size() == 3);
127 assert(c
.count(1) == 1);
128 assert(c
.count(3) == 1);
129 assert(c
.count(4) == 1);
131 assert(c
.erase(4) == 1);
132 assert(c
.size() == 2);
133 assert(c
.count(1) == 1);
134 assert(c
.count(3) == 1);
136 assert(c
.erase(4) == 0);
137 assert(c
.size() == 2);
138 assert(c
.count(1) == 1);
139 assert(c
.count(3) == 1);
141 assert(c
.erase(1) == 1);
142 assert(c
.size() == 1);
143 assert(c
.count(3) == 1);
145 assert(c
.erase(1) == 0);
146 assert(c
.size() == 1);
147 assert(c
.count(3) == 1);
149 assert(c
.erase(3) == 1);
150 assert(c
.size() == 0);
152 assert(c
.erase(3) == 0);
153 assert(c
.size() == 0);
156 typedef std::unordered_set
<int> C
;
158 for ( int i
= 0; i
< 10; ++i
) {
163 C::iterator i
= m2
.begin();
165 while (i
!= m2
.end()) {
172 assert (only_deletions (m
, m2
));