1 // { dg-do run { target c++11 } }
3 // 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com>
5 // Copyright (C) 2010-2025 Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
22 #include <unordered_set>
24 #include <testsuite_hooks.h>
29 get_nb_bucket_elems(const std::unordered_set
<std::string
>& us
)
32 for (std::size_t b
= 0; b
!= us
.bucket_count(); ++b
)
33 nb
+= us
.bucket_size(b
);
40 typedef std::unordered_set
<std::string
> Set
;
41 typedef Set::iterator iterator
;
42 typedef Set::const_iterator const_iterator
;
46 s1
.insert("because to why");
47 s1
.insert("the stockholm syndrome");
48 s1
.insert("a cereous night");
51 s1
.insert("the way you are when");
52 s1
.insert("tillsammans");
53 s1
.insert("umbra/penumbra");
54 s1
.insert("belonging (no longer mix)");
55 s1
.insert("one line behind");
56 VERIFY( s1
.size() == 10 );
57 VERIFY( get_nb_bucket_elems(s1
) == s1
.size() );
58 VERIFY( distance(s1
.begin(), s1
.end()) - s1
.size() == 0 );
60 VERIFY( s1
.erase("eeilo") == 1 );
61 VERIFY( s1
.size() == 9 );
62 VERIFY( get_nb_bucket_elems(s1
) == s1
.size() );
63 VERIFY( distance(s1
.begin(), s1
.end()) - s1
.size() == 0 );
64 iterator it1
= s1
.find("eeilo");
65 VERIFY( it1
== s1
.end() );
67 VERIFY( s1
.erase("tillsammans") == 1 );
68 VERIFY( s1
.size() == 8 );
69 VERIFY( get_nb_bucket_elems(s1
) == s1
.size() );
70 VERIFY( distance(s1
.begin(), s1
.end()) - s1
.size() == 0 );
71 iterator it2
= s1
.find("tillsammans");
72 VERIFY( it2
== s1
.end() );
74 // Must work (see DR 526)
75 iterator it3
= s1
.find("belonging (no longer mix)");
76 VERIFY( it3
!= s1
.end() );
77 VERIFY( s1
.erase(*it3
) == 1 );
78 VERIFY( s1
.size() == 7 );
79 VERIFY( get_nb_bucket_elems(s1
) == s1
.size() );
80 VERIFY( distance(s1
.begin(), s1
.end()) - s1
.size() == 0 );
81 it3
= s1
.find("belonging (no longer mix)");
82 VERIFY( it3
== s1
.end() );
84 VERIFY( !s1
.erase("abra") );
85 VERIFY( s1
.size() == 7 );
86 VERIFY( get_nb_bucket_elems(s1
) == s1
.size() );
87 VERIFY( distance(s1
.begin(), s1
.end()) - s1
.size() == 0 );
89 VERIFY( !s1
.erase("eeilo") );
90 VERIFY( s1
.size() == 7 );
92 VERIFY( s1
.erase("because to why") == 1 );
93 VERIFY( s1
.size() == 6 );
94 VERIFY( get_nb_bucket_elems(s1
) == s1
.size() );
95 VERIFY( distance(s1
.begin(), s1
.end()) - s1
.size() == 0 );
96 iterator it4
= s1
.find("because to why");
97 VERIFY( it4
== s1
.end() );
99 iterator it5
= s1
.find("umbra/penumbra");
100 iterator it6
= s1
.find("one line behind");
101 VERIFY( it5
!= s1
.end() );
102 VERIFY( it6
!= s1
.end() );
104 VERIFY( s1
.find("the stockholm syndrome") != s1
.end() );
105 VERIFY( s1
.find("a cereous night") != s1
.end() );
106 VERIFY( s1
.find("the way you are when") != s1
.end() );
107 VERIFY( s1
.find("a cereous night") != s1
.end() );
109 VERIFY( s1
.erase(*it5
) == 1 );
110 VERIFY( s1
.size() == 5 );
111 VERIFY( get_nb_bucket_elems(s1
) == s1
.size() );
112 VERIFY( distance(s1
.begin(), s1
.end()) - s1
.size() == 0 );
113 it5
= s1
.find("umbra/penumbra");
114 VERIFY( it5
== s1
.end() );
116 VERIFY( s1
.erase(*it6
) == 1 );
117 VERIFY( s1
.size() == 4 );
118 VERIFY( get_nb_bucket_elems(s1
) == s1
.size() );
119 VERIFY( distance(s1
.begin(), s1
.end()) - s1
.size() == 0 );
120 it6
= s1
.find("one line behind");
121 VERIFY( it6
== s1
.end() );
123 iterator it7
= s1
.begin();
129 VERIFY( s1
.erase(*it8
) == 1 );
130 VERIFY( s1
.size() == 3 );
131 VERIFY( get_nb_bucket_elems(s1
) == s1
.size() );
132 VERIFY( distance(s1
.begin(), s1
.end()) - s1
.size() == 0 );
133 VERIFY( ++it7
== it9
);
137 iterator it11
= it10
;
139 VERIFY( s1
.erase(*it9
) == 1 );
140 VERIFY( get_nb_bucket_elems(s1
) == s1
.size() );
141 VERIFY( distance(s1
.begin(), s1
.end()) - s1
.size() == 0 );
142 VERIFY( s1
.size() == 2 );
143 VERIFY( ++it10
== s1
.end() );
145 VERIFY( s1
.erase(s1
.begin()) != s1
.end() );
146 VERIFY( s1
.size() == 1 );
147 VERIFY( get_nb_bucket_elems(s1
) == s1
.size() );
148 VERIFY( distance(s1
.begin(), s1
.end()) - s1
.size() == 0 );
149 VERIFY( s1
.begin() == it11
);
151 VERIFY( s1
.erase(*s1
.begin()) == 1 );
152 VERIFY( s1
.size() == 0 );
153 VERIFY( get_nb_bucket_elems(s1
) == s1
.size() );
154 VERIFY( distance(s1
.begin(), s1
.end()) - s1
.size() == 0 );
155 VERIFY( s1
.begin() == s1
.end() );