]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/2.cc
Use effective-target instead of -std options
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_multiset / erase / 2.cc
1 // { dg-do run { target c++11 } }
2
3 // Copyright (C) 2011-2016 Free Software Foundation, Inc.
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_set>
21 #include <string>
22 #include <testsuite_hooks.h>
23
24 namespace
25 {
26 std::size_t
27 get_nb_bucket_elems(const std::unordered_multiset<std::string>& us)
28 {
29 std::size_t nb = 0;
30 for (std::size_t b = 0; b != us.bucket_count(); ++b)
31 nb += us.bucket_size(b);
32 return nb;
33 }
34 }
35
36 void test01()
37 {
38 bool test __attribute__((unused)) = true;
39
40 typedef std::unordered_multiset<std::string> Mset;
41 typedef Mset::iterator iterator;
42 typedef Mset::const_iterator const_iterator;
43
44 Mset ms1;
45
46 ms1.insert("foo");
47 ms1.insert("foo");
48 ms1.insert("foo");
49 ms1.insert("foo");
50 ms1.insert("foo");
51 ms1.insert("foo");
52 ms1.insert("bar");
53 ms1.insert("bar");
54 ms1.insert("bar");
55 ms1.insert("bar");
56 ms1.insert("bar");
57 ms1.insert("bar");
58 VERIFY( ms1.size() == 12 );
59 VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
60 VERIFY( distance(ms1.begin(), ms1.end()) - ms1.size() == 0 );
61
62 VERIFY( ms1.erase(ms1.begin()) != ms1.end() );
63 VERIFY( ms1.size() == 11 );
64 VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
65 VERIFY( distance(ms1.begin(), ms1.end()) - ms1.size() == 0 );
66
67 auto it = ms1.begin();
68 advance(it, 2);
69 VERIFY( ms1.erase(ms1.begin(), it) != ms1.end() );
70 VERIFY( ms1.size() == 9 );
71 VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
72 VERIFY( distance(ms1.begin(), ms1.end()) - ms1.size() == 0 );
73
74 VERIFY( ms1.erase(*(ms1.begin())) == 3 );
75 VERIFY( ms1.size() == 6 );
76 VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
77 VERIFY( distance(ms1.begin(), ms1.end()) - ms1.size() == 0 );
78
79 VERIFY( ms1.erase(ms1.begin(), ms1.end()) == ms1.end() );
80 VERIFY( ms1.empty() );
81 VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
82 VERIFY( distance(ms1.begin(), ms1.end()) - ms1.size() == 0 );
83 }
84
85 int main()
86 {
87 test01();
88 return 0;
89 }