1 // { dg-options "-std=gnu++0x" }
3 // 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com>
5 // Copyright (C) 2010 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_multiset
<std::string
>& us
)
32 for (std::size_t b
= 0; b
!= us
.bucket_count(); ++b
)
33 nb
+= us
.bucket_size(b
);
40 bool test
__attribute__((unused
)) = true;
42 typedef std::unordered_multiset
<std::string
> Mset
;
43 typedef Mset::iterator iterator
;
44 typedef Mset::const_iterator const_iterator
;
48 ms1
.insert("because to why");
49 ms1
.insert("the stockholm syndrome");
50 ms1
.insert("a cereous night");
52 ms1
.insert("protean");
53 ms1
.insert("the way you are when");
54 ms1
.insert("tillsammans");
55 ms1
.insert("umbra/penumbra");
56 ms1
.insert("belonging (no longer mix)");
57 ms1
.insert("one line behind");
58 ms1
.insert("because to why");
59 VERIFY( ms1
.size() == 11 );
60 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
62 VERIFY( ms1
.erase("eeilo") == 1 );
63 VERIFY( ms1
.size() == 10 );
64 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
65 iterator it1
= ms1
.find("eeilo");
66 VERIFY( it1
== ms1
.end() );
68 VERIFY( ms1
.erase("tillsammans") == 1 );
69 VERIFY( ms1
.size() == 9 );
70 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
71 iterator it2
= ms1
.find("tillsammans");
72 VERIFY( it2
== ms1
.end() );
74 // Must work (see DR 526)
75 iterator it3
= ms1
.find("belonging (no longer mix)");
76 VERIFY( it3
!= ms1
.end() );
77 VERIFY( ms1
.erase(*it3
) == 1 );
78 VERIFY( ms1
.size() == 8 );
79 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
80 it3
= ms1
.find("belonging (no longer mix)");
81 VERIFY( it3
== ms1
.end() );
83 VERIFY( !ms1
.erase("abra") );
84 VERIFY( ms1
.size() == 8 );
85 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
87 VERIFY( !ms1
.erase("eeilo") );
88 VERIFY( ms1
.size() == 8 );
90 VERIFY( ms1
.erase("because to why") == 2 );
91 VERIFY( ms1
.size() == 6 );
92 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
93 iterator it4
= ms1
.find("because to why");
94 VERIFY( it4
== ms1
.end() );
96 iterator it5
= ms1
.find("umbra/penumbra");
97 iterator it6
= ms1
.find("one line behind");
98 VERIFY( it5
!= ms1
.end() );
99 VERIFY( it6
!= ms1
.end() );
101 VERIFY( ms1
.find("the stockholm syndrome") != ms1
.end() );
102 VERIFY( ms1
.find("a cereous night") != ms1
.end() );
103 VERIFY( ms1
.find("the way you are when") != ms1
.end() );
104 VERIFY( ms1
.find("a cereous night") != ms1
.end() );
106 VERIFY( ms1
.erase(*it5
) == 1 );
107 VERIFY( ms1
.size() == 5 );
108 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
109 it5
= ms1
.find("umbra/penumbra");
110 VERIFY( it5
== ms1
.end() );
112 VERIFY( ms1
.erase(*it6
) == 1 );
113 VERIFY( ms1
.size() == 4 );
114 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
115 it6
= ms1
.find("one line behind");
116 VERIFY( it6
== ms1
.end() );
118 iterator it7
= ms1
.begin();
124 VERIFY( ms1
.erase(*it8
) == 1 );
125 VERIFY( ms1
.size() == 3 );
126 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
127 VERIFY( ++it7
== it9
);
131 iterator it11
= it10
;
133 VERIFY( ms1
.erase(*it9
) == 1 );
134 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
135 VERIFY( ms1
.size() == 2 );
136 VERIFY( ++it10
== ms1
.end() );
138 VERIFY( ms1
.erase(ms1
.begin()) != ms1
.end() );
139 VERIFY( ms1
.size() == 1 );
140 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
141 VERIFY( ms1
.begin() == it11
);
143 VERIFY( ms1
.erase(*ms1
.begin()) == 1 );
144 VERIFY( ms1
.size() == 0 );
145 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
146 VERIFY( ms1
.begin() == ms1
.end() );