1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2011-2020 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 #include <unordered_map>
22 #include <testsuite_hooks.h>
27 get_nb_bucket_elems(const std::unordered_multimap
<std::string
, int>& um
)
30 for (std::size_t b
= 0; b
!= um
.bucket_count(); ++b
)
31 nb
+= um
.bucket_size(b
);
38 typedef std::unordered_multimap
<std::string
, int> Mmap
;
39 typedef Mmap::iterator iterator
;
40 typedef Mmap::const_iterator const_iterator
;
41 typedef Mmap::value_type value_type
;
45 mm1
.insert(value_type("foo", 10));
46 mm1
.insert(value_type("foo", 11));
47 mm1
.insert(value_type("foo", 12));
48 mm1
.insert(value_type("foo", 13));
49 mm1
.insert(value_type("foo", 14));
50 mm1
.insert(value_type("foo", 15));
51 mm1
.insert(value_type("bar", 20));
52 mm1
.insert(value_type("bar", 21));
53 mm1
.insert(value_type("bar", 22));
54 mm1
.insert(value_type("bar", 23));
55 mm1
.insert(value_type("bar", 24));
56 mm1
.insert(value_type("bar", 25));
57 VERIFY( mm1
.size() == 12 );
58 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
59 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
61 VERIFY( mm1
.erase(mm1
.begin()) != mm1
.end() );
62 VERIFY( mm1
.size() == 11 );
63 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
64 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
66 auto it
= mm1
.begin();
68 VERIFY( mm1
.erase(mm1
.begin(), it
) != mm1
.end() );
69 VERIFY( mm1
.size() == 9 );
70 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
71 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
73 VERIFY( mm1
.erase(mm1
.begin()->first
) == 3 );
74 VERIFY( mm1
.size() == 6 );
75 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
76 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );
78 VERIFY( mm1
.erase(mm1
.begin(), mm1
.end()) == mm1
.end() );
79 VERIFY( mm1
.empty() );
80 VERIFY( get_nb_bucket_elems(mm1
) == mm1
.size() );
81 VERIFY( distance(mm1
.begin(), mm1
.end()) - mm1
.size() == 0 );