]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/24061-multiset.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_multiset / erase / 24061-multiset.cc
1 // { dg-do run { target c++11 } }
2
3 // 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com>
4 //
5 // Copyright (C) 2010-2020 Free Software Foundation, Inc.
6 //
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)
11 // any later version.
12 //
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.
17 //
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/>.
21
22 #include <unordered_set>
23 #include <string>
24 #include <testsuite_hooks.h>
25
26 namespace
27 {
28 std::size_t
29 get_nb_bucket_elems(const std::unordered_multiset<std::string>& us)
30 {
31 std::size_t nb = 0;
32 for (std::size_t b = 0; b != us.bucket_count(); ++b)
33 {
34 nb += us.bucket_size(b);
35 }
36 return nb;
37 }
38 }
39
40 // libstdc++/24061
41 void test01()
42 {
43 typedef std::unordered_multiset<std::string> Mset;
44 typedef Mset::iterator iterator;
45 typedef Mset::const_iterator const_iterator;
46
47 Mset ms1;
48
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");
56 ms1.insert("only");
57 ms1.insert("getting smaller");
58 ms1.insert("sunspots");
59
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() );
65
66 iterator it1 = ms1.begin();
67 ++it1;
68 iterator it2 = it1;
69 ++it2;
70 iterator it3 = ms1.erase(it1);
71 VERIFY( ms1.size() == 12 );
72 VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
73 VERIFY( it3 == it2 );
74 VERIFY( *it3 == *it2 );
75
76 iterator it4 = ms1.begin();
77 ++it4;
78 ++it4;
79 ++it4;
80 iterator it5 = it4;
81 ++it5;
82 ++it5;
83 iterator it6 = ms1.erase(it4, it5);
84 VERIFY( ms1.size() == 10 );
85 VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
86 VERIFY( it6 == it5 );
87 VERIFY( *it6 == *it5 );
88
89 const_iterator it7 = ms1.begin();
90 ++it7;
91 ++it7;
92 ++it7;
93 const_iterator it8 = it7;
94 ++it8;
95 const_iterator it9 = ms1.erase(it7);
96 VERIFY( ms1.size() == 9 );
97 VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
98 VERIFY( it9 == it8 );
99 VERIFY( *it9 == *it8 );
100
101 const_iterator it10 = ms1.begin();
102 ++it10;
103 const_iterator it11 = it10;
104 ++it11;
105 ++it11;
106 ++it11;
107 ++it11;
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 );
113
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() );
119 }
120
121 int main()
122 {
123 test01();
124 return 0;
125 }