]> git.ipfire.org Git - thirdparty/gcc.git/blame - 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
CommitLineData
4415f7a5 1// { dg-options "-std=gnu++11" }
3b2524b1
PC
2
3// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com>
4//
818ab71a 5// Copyright (C) 2010-2016 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
da29608a
FD
26namespace
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
3b2524b1
PC
40// libstdc++/24061
41void test01()
42{
43 bool test __attribute__((unused)) = true;
44
45 typedef std::unordered_multiset<std::string> Mset;
46 typedef Mset::iterator iterator;
47 typedef Mset::const_iterator const_iterator;
48
49 Mset ms1;
50
51 ms1.insert("all the love in the world");
52 ms1.insert("you know what you are?");
53 ms1.insert("the collector");
54 ms1.insert("the hand that feeds");
55 ms1.insert("love is not enough");
56 ms1.insert("every day is exactly the same");
57 ms1.insert("with teeth");
58 ms1.insert("only");
59 ms1.insert("getting smaller");
60 ms1.insert("sunspots");
61
62 ms1.insert("the hand that feeds");
63 ms1.insert("love is not enough");
64 ms1.insert("every day is exactly the same");
65 VERIFY( ms1.size() == 13 );
da29608a 66 VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
3b2524b1
PC
67
68 iterator it1 = ms1.begin();
69 ++it1;
70 iterator it2 = it1;
71 ++it2;
d723ced2 72 iterator it3 = ms1.erase(it1);
3b2524b1 73 VERIFY( ms1.size() == 12 );
da29608a 74 VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
d723ced2
PC
75 VERIFY( it3 == it2 );
76 VERIFY( *it3 == *it2 );
3b2524b1
PC
77
78 iterator it4 = ms1.begin();
79 ++it4;
80 ++it4;
81 ++it4;
82 iterator it5 = it4;
83 ++it5;
84 ++it5;
d723ced2 85 iterator it6 = ms1.erase(it4, it5);
3b2524b1 86 VERIFY( ms1.size() == 10 );
da29608a 87 VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
d723ced2
PC
88 VERIFY( it6 == it5 );
89 VERIFY( *it6 == *it5 );
3b2524b1
PC
90
91 const_iterator it7 = ms1.begin();
92 ++it7;
93 ++it7;
94 ++it7;
95 const_iterator it8 = it7;
96 ++it8;
d723ced2 97 const_iterator it9 = ms1.erase(it7);
3b2524b1 98 VERIFY( ms1.size() == 9 );
da29608a 99 VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
d723ced2
PC
100 VERIFY( it9 == it8 );
101 VERIFY( *it9 == *it8 );
3b2524b1
PC
102
103 const_iterator it10 = ms1.begin();
104 ++it10;
105 const_iterator it11 = it10;
106 ++it11;
107 ++it11;
108 ++it11;
109 ++it11;
d723ced2 110 const_iterator it12 = ms1.erase(it10, it11);
3b2524b1 111 VERIFY( ms1.size() == 5 );
da29608a 112 VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
d723ced2
PC
113 VERIFY( it12 == it11 );
114 VERIFY( *it12 == *it11 );
3b2524b1 115
d723ced2 116 iterator it13 = ms1.erase(ms1.begin(), ms1.end());
3b2524b1 117 VERIFY( ms1.size() == 0 );
da29608a 118 VERIFY( get_nb_bucket_elems(ms1) == ms1.size() );
d723ced2
PC
119 VERIFY( it13 == ms1.end() );
120 VERIFY( it13 == ms1.begin() );
3b2524b1
PC
121}
122
123int main()
124{
125 test01();
126 return 0;
127}