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_map>
24 #include <testsuite_hooks.h>
29 get_nb_bucket_elems(const std::unordered_multimap
<std::string
, int>& us
)
32 for (std::size_t b
= 0; b
!= us
.bucket_count(); ++b
)
33 nb
+= us
.bucket_size(b
);
40 typedef std::unordered_multimap
<std::string
, int> Mmap
;
41 typedef Mmap::iterator iterator
;
42 typedef Mmap::const_iterator const_iterator
;
43 typedef Mmap::value_type value_type
;
47 mm1
.insert(value_type("because to why", 1));
48 mm1
.insert(value_type("the stockholm syndrome", 2));
49 mm1
.insert(value_type("a cereous night", 3));
50 mm1
.insert(value_type("eeilo", 4));
51 mm1
.insert(value_type("protean", 5));
52 mm1
.insert(value_type("the way you are when", 6));
53 mm1
.insert(value_type("tillsammans", 7));
54 mm1
.insert(value_type("umbra/penumbra", 8));
55 mm1
.insert(value_type("belonging (no longer mix)", 9));
56 mm1
.insert(value_type("one line behind", 10));
57 mm1
.insert(value_type("because to why", 11));
58 VERIFY( mm1
.size() == 11 );
59 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
60 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
62 VERIFY( mm1
.erase("eeilo") == 1 );
63 VERIFY( mm1
.size() == 10 );
64 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
65 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
66 iterator it1
= mm1
.find("eeilo");
67 VERIFY( it1
== mm1
.end() );
69 VERIFY( mm1
.erase("tillsammans") == 1 );
70 VERIFY( mm1
.size() == 9 );
71 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
72 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
73 iterator it2
= mm1
.find("tillsammans");
74 VERIFY( it2
== mm1
.end() );
76 // Must work (see DR 526)
77 iterator it3
= mm1
.find("belonging (no longer mix)");
78 VERIFY( it3
!= mm1
.end() );
79 VERIFY( mm1
.erase(it3
->first
) == 1 );
80 VERIFY( mm1
.size() == 8 );
81 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
82 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
83 it3
= mm1
.find("belonging (no longer mix)");
84 VERIFY( it3
== mm1
.end() );
86 VERIFY( !mm1
.erase("abra") );
87 VERIFY( mm1
.size() == 8 );
88 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
89 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
91 VERIFY( !mm1
.erase("eeilo") );
92 VERIFY( mm1
.size() == 8 );
94 VERIFY( mm1
.erase("because to why") == 2 );
95 VERIFY( mm1
.size() == 6 );
96 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
97 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
98 iterator it4
= mm1
.find("because to why");
99 VERIFY( it4
== mm1
.end() );
101 iterator it5
= mm1
.find("umbra/penumbra");
102 iterator it6
= mm1
.find("one line behind");
103 VERIFY( it5
!= mm1
.end() );
104 VERIFY( it6
!= mm1
.end() );
106 VERIFY( mm1
.find("the stockholm syndrome") != mm1
.end() );
107 VERIFY( mm1
.find("a cereous night") != mm1
.end() );
108 VERIFY( mm1
.find("the way you are when") != mm1
.end() );
109 VERIFY( mm1
.find("a cereous night") != mm1
.end() );
111 VERIFY( mm1
.erase(it5
->first
) == 1 );
112 VERIFY( mm1
.size() == 5 );
113 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
114 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
115 it5
= mm1
.find("umbra/penumbra");
116 VERIFY( it5
== mm1
.end() );
118 VERIFY( mm1
.erase(it6
->first
) == 1 );
119 VERIFY( mm1
.size() == 4 );
120 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
121 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
122 it6
= mm1
.find("one line behind");
123 VERIFY( it6
== mm1
.end() );
125 iterator it7
= mm1
.begin();
131 VERIFY( mm1
.erase(it8
->first
) == 1 );
132 VERIFY( mm1
.size() == 3 );
133 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
134 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
135 VERIFY( ++it7
== it9
);
139 iterator it11
= it10
;
141 VERIFY( mm1
.erase(it9
->first
) == 1 );
142 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
143 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
144 VERIFY( mm1
.size() == 2 );
145 VERIFY( ++it10
== mm1
.end() );
147 VERIFY( mm1
.erase(mm1
.begin()) != mm1
.end() );
148 VERIFY( mm1
.size() == 1 );
149 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
150 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
151 VERIFY( mm1
.begin() == it11
);
153 VERIFY( mm1
.erase(mm1
.begin()->first
) == 1 );
154 VERIFY( mm1
.size() == 0 );
155 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
156 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
157 VERIFY( mm1
.begin() == mm1
.end() );