]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/unordered_set/erase/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_set / erase / 1.cc
CommitLineData
4415f7a5 1// { dg-options "-std=gnu++11" }
3b2524b1
PC
2
3// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com>
4//
5624e564 5// Copyright (C) 2010-2015 Free Software Foundation, Inc.
3b2524b1
PC
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
40207762
FD
26namespace
27{
28 std::size_t
29 get_nb_bucket_elems(const std::unordered_set<std::string>& us)
30 {
31 std::size_t nb = 0;
32 for (std::size_t b = 0; b != us.bucket_count(); ++b)
33 nb += us.bucket_size(b);
34 return nb;
35 }
36}
37
3b2524b1
PC
38void test01()
39{
40 bool test __attribute__((unused)) = true;
41
42 typedef std::unordered_set<std::string> Set;
43 typedef Set::iterator iterator;
44 typedef Set::const_iterator const_iterator;
45
46 Set s1;
47
48 s1.insert("because to why");
49 s1.insert("the stockholm syndrome");
50 s1.insert("a cereous night");
51 s1.insert("eeilo");
52 s1.insert("protean");
53 s1.insert("the way you are when");
54 s1.insert("tillsammans");
55 s1.insert("umbra/penumbra");
56 s1.insert("belonging (no longer mix)");
57 s1.insert("one line behind");
58 VERIFY( s1.size() == 10 );
40207762 59 VERIFY( get_nb_bucket_elems(s1) == s1.size() );
d847ec80 60 VERIFY( distance(s1.begin(), s1.end()) - s1.size() == 0 );
3b2524b1
PC
61
62 VERIFY( s1.erase("eeilo") == 1 );
63 VERIFY( s1.size() == 9 );
40207762 64 VERIFY( get_nb_bucket_elems(s1) == s1.size() );
d847ec80 65 VERIFY( distance(s1.begin(), s1.end()) - s1.size() == 0 );
3b2524b1
PC
66 iterator it1 = s1.find("eeilo");
67 VERIFY( it1 == s1.end() );
68
69 VERIFY( s1.erase("tillsammans") == 1 );
70 VERIFY( s1.size() == 8 );
40207762 71 VERIFY( get_nb_bucket_elems(s1) == s1.size() );
d847ec80 72 VERIFY( distance(s1.begin(), s1.end()) - s1.size() == 0 );
3b2524b1
PC
73 iterator it2 = s1.find("tillsammans");
74 VERIFY( it2 == s1.end() );
75
76 // Must work (see DR 526)
77 iterator it3 = s1.find("belonging (no longer mix)");
78 VERIFY( it3 != s1.end() );
79 VERIFY( s1.erase(*it3) == 1 );
80 VERIFY( s1.size() == 7 );
40207762 81 VERIFY( get_nb_bucket_elems(s1) == s1.size() );
d847ec80 82 VERIFY( distance(s1.begin(), s1.end()) - s1.size() == 0 );
3b2524b1
PC
83 it3 = s1.find("belonging (no longer mix)");
84 VERIFY( it3 == s1.end() );
85
86 VERIFY( !s1.erase("abra") );
87 VERIFY( s1.size() == 7 );
40207762 88 VERIFY( get_nb_bucket_elems(s1) == s1.size() );
d847ec80 89 VERIFY( distance(s1.begin(), s1.end()) - s1.size() == 0 );
3b2524b1
PC
90
91 VERIFY( !s1.erase("eeilo") );
92 VERIFY( s1.size() == 7 );
93
94 VERIFY( s1.erase("because to why") == 1 );
95 VERIFY( s1.size() == 6 );
40207762 96 VERIFY( get_nb_bucket_elems(s1) == s1.size() );
d847ec80 97 VERIFY( distance(s1.begin(), s1.end()) - s1.size() == 0 );
3b2524b1
PC
98 iterator it4 = s1.find("because to why");
99 VERIFY( it4 == s1.end() );
100
101 iterator it5 = s1.find("umbra/penumbra");
102 iterator it6 = s1.find("one line behind");
103 VERIFY( it5 != s1.end() );
104 VERIFY( it6 != s1.end() );
105
106 VERIFY( s1.find("the stockholm syndrome") != s1.end() );
107 VERIFY( s1.find("a cereous night") != s1.end() );
108 VERIFY( s1.find("the way you are when") != s1.end() );
109 VERIFY( s1.find("a cereous night") != s1.end() );
110
111 VERIFY( s1.erase(*it5) == 1 );
112 VERIFY( s1.size() == 5 );
40207762 113 VERIFY( get_nb_bucket_elems(s1) == s1.size() );
d847ec80 114 VERIFY( distance(s1.begin(), s1.end()) - s1.size() == 0 );
3b2524b1
PC
115 it5 = s1.find("umbra/penumbra");
116 VERIFY( it5 == s1.end() );
117
118 VERIFY( s1.erase(*it6) == 1 );
119 VERIFY( s1.size() == 4 );
40207762 120 VERIFY( get_nb_bucket_elems(s1) == s1.size() );
d847ec80 121 VERIFY( distance(s1.begin(), s1.end()) - s1.size() == 0 );
3b2524b1
PC
122 it6 = s1.find("one line behind");
123 VERIFY( it6 == s1.end() );
124
125 iterator it7 = s1.begin();
126 iterator it8 = it7;
127 ++it8;
128 iterator it9 = it8;
129 ++it9;
130
131 VERIFY( s1.erase(*it8) == 1 );
132 VERIFY( s1.size() == 3 );
40207762 133 VERIFY( get_nb_bucket_elems(s1) == s1.size() );
d847ec80 134 VERIFY( distance(s1.begin(), s1.end()) - s1.size() == 0 );
3b2524b1
PC
135 VERIFY( ++it7 == it9 );
136
137 iterator it10 = it9;
138 ++it10;
139 iterator it11 = it10;
140
141 VERIFY( s1.erase(*it9) == 1 );
40207762 142 VERIFY( get_nb_bucket_elems(s1) == s1.size() );
d847ec80 143 VERIFY( distance(s1.begin(), s1.end()) - s1.size() == 0 );
3b2524b1
PC
144 VERIFY( s1.size() == 2 );
145 VERIFY( ++it10 == s1.end() );
146
d723ced2 147 VERIFY( s1.erase(s1.begin()) != s1.end() );
3b2524b1 148 VERIFY( s1.size() == 1 );
40207762 149 VERIFY( get_nb_bucket_elems(s1) == s1.size() );
d847ec80 150 VERIFY( distance(s1.begin(), s1.end()) - s1.size() == 0 );
3b2524b1
PC
151 VERIFY( s1.begin() == it11 );
152
153 VERIFY( s1.erase(*s1.begin()) == 1 );
154 VERIFY( s1.size() == 0 );
40207762 155 VERIFY( get_nb_bucket_elems(s1) == s1.size() );
d847ec80 156 VERIFY( distance(s1.begin(), s1.end()) - s1.size() == 0 );
3b2524b1
PC
157 VERIFY( s1.begin() == s1.end() );
158}
159
160int main()
161{
162 test01();
163 return 0;
164}