1 // { dg-do run { target c++11 } }
3 // 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com>
5 // Copyright (C) 2010-2020 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
)
34 nb
+= us
.bucket_size(b
);
43 typedef std::unordered_multiset
<std::string
> Mset
;
44 typedef Mset::iterator iterator
;
45 typedef Mset::const_iterator const_iterator
;
49 ms1
.insert("all the love in the world");
50 ms1
.insert("you know what you are?");
51 ms1
.insert("the collector");
52 ms1
.insert("the hand that feeds");
53 ms1
.insert("love is not enough");
54 ms1
.insert("every day is exactly the same");
55 ms1
.insert("with teeth");
57 ms1
.insert("getting smaller");
58 ms1
.insert("sunspots");
60 ms1
.insert("the hand that feeds");
61 ms1
.insert("love is not enough");
62 ms1
.insert("every day is exactly the same");
63 VERIFY( ms1
.size() == 13 );
64 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
66 iterator it1
= ms1
.begin();
70 iterator it3
= ms1
.erase(it1
);
71 VERIFY( ms1
.size() == 12 );
72 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
74 VERIFY( *it3
== *it2
);
76 iterator it4
= ms1
.begin();
83 iterator it6
= ms1
.erase(it4
, it5
);
84 VERIFY( ms1
.size() == 10 );
85 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
87 VERIFY( *it6
== *it5
);
89 const_iterator it7
= ms1
.begin();
93 const_iterator it8
= it7
;
95 const_iterator it9
= ms1
.erase(it7
);
96 VERIFY( ms1
.size() == 9 );
97 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
99 VERIFY( *it9
== *it8
);
101 const_iterator it10
= ms1
.begin();
103 const_iterator it11
= it10
;
108 const_iterator it12
= ms1
.erase(it10
, it11
);
109 VERIFY( ms1
.size() == 5 );
110 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
111 VERIFY( it12
== it11
);
112 VERIFY( *it12
== *it11
);
114 iterator it13
= ms1
.erase(ms1
.begin(), ms1
.end());
115 VERIFY( ms1
.size() == 0 );
116 VERIFY( get_nb_bucket_elems(ms1
) == ms1
.size() );
117 VERIFY( it13
== ms1
.end() );
118 VERIFY( it13
== ms1
.begin() );