]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_multimap / erase / 2.cc
CommitLineData
8868286e 1// { dg-options "-std=gnu++11" }
9f119d65 2
f1717362 3// Copyright (C) 2011-2016 Free Software Foundation, Inc.
9f119d65 4//
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)
9// any later version.
10//
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.
15//
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/>.
19
20#include <unordered_map>
21#include <string>
22#include <testsuite_hooks.h>
23
24namespace
25{
26 std::size_t
27 get_nb_bucket_elems(const std::unordered_multimap<std::string, int>& um)
28 {
29 std::size_t nb = 0;
30 for (std::size_t b = 0; b != um.bucket_count(); ++b)
31 nb += um.bucket_size(b);
32 return nb;
33 }
34}
35
36void test01()
37{
38 bool test __attribute__((unused)) = true;
39
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;
44
45 Mmap mm1;
46
47 mm1.insert(value_type("foo", 10));
48 mm1.insert(value_type("foo", 11));
49 mm1.insert(value_type("foo", 12));
50 mm1.insert(value_type("foo", 13));
51 mm1.insert(value_type("foo", 14));
52 mm1.insert(value_type("foo", 15));
53 mm1.insert(value_type("bar", 20));
54 mm1.insert(value_type("bar", 21));
55 mm1.insert(value_type("bar", 22));
56 mm1.insert(value_type("bar", 23));
57 mm1.insert(value_type("bar", 24));
58 mm1.insert(value_type("bar", 25));
59 VERIFY( mm1.size() == 12 );
60 VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
664ecbbe 61 VERIFY( distance(mm1.begin(), mm1.end()) - mm1.size() == 0 );
9f119d65 62
63 VERIFY( mm1.erase(mm1.begin()) != mm1.end() );
64 VERIFY( mm1.size() == 11 );
65 VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
664ecbbe 66 VERIFY( distance(mm1.begin(), mm1.end()) - mm1.size() == 0 );
9f119d65 67
68 auto it = mm1.begin();
69 advance(it, 2);
70 VERIFY( mm1.erase(mm1.begin(), it) != mm1.end() );
71 VERIFY( mm1.size() == 9 );
72 VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
664ecbbe 73 VERIFY( distance(mm1.begin(), mm1.end()) - mm1.size() == 0 );
9f119d65 74
75 VERIFY( mm1.erase(mm1.begin()->first) == 3 );
76 VERIFY( mm1.size() == 6 );
77 VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
664ecbbe 78 VERIFY( distance(mm1.begin(), mm1.end()) - mm1.size() == 0 );
9f119d65 79
80 VERIFY( mm1.erase(mm1.begin(), mm1.end()) == mm1.end() );
81 VERIFY( mm1.empty() );
82 VERIFY( get_nb_bucket_elems(mm1) == mm1.size() );
664ecbbe 83 VERIFY( distance(mm1.begin(), mm1.end()) - mm1.size() == 0 );
9f119d65 84}
85
86int main()
87{
88 test01();
89 return 0;
90}