1// 2005-10-08  Paolo Carlini  <pcarlini@suse.de>
2//
3// Copyright (C) 2005 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 2, 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 COPYING.  If not, write to the Free
18// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19// USA.
20
21// 6.3.4.5  Class template unordered_multiset
22
23#include <tr1/unordered_set>
24#include <string>
25#include <testsuite_hooks.h>
26
27// libstdc++/24061
28void test01()
29{
30  bool test __attribute__((unused)) = true;
31
32  typedef std::tr1::unordered_multiset<std::string> Mset;
33  typedef Mset::iterator       iterator;
34  typedef Mset::const_iterator const_iterator;
35
36  Mset ms1;
37
38  ms1.insert("all the love in the world");
39  ms1.insert("you know what you are?");
40  ms1.insert("the collector");
41  ms1.insert("the hand that feeds");
42  ms1.insert("love is not enough");
43  ms1.insert("every day is exactly the same");
44  ms1.insert("with teeth");
45  ms1.insert("only");
46  ms1.insert("getting smaller");
47  ms1.insert("sunspots");
48
49  ms1.insert("the hand that feeds");
50  ms1.insert("love is not enough");
51  ms1.insert("every day is exactly the same");
52  VERIFY( ms1.size() == 13 );
53
54  iterator it1 = ms1.begin();
55  ++it1;
56  iterator it2 = it1;
57  ++it2;
58  iterator it3 = ms1.erase(it1);
59  VERIFY( ms1.size() == 12 );
60  VERIFY( it3 == it2 );
61  VERIFY( *it3 == *it2 );
62
63  iterator it4 = ms1.begin();
64  ++it4;
65  ++it4;
66  ++it4;
67  iterator it5 = it4;
68  ++it5;
69  ++it5;
70  iterator it6 = ms1.erase(it4, it5);
71  VERIFY( ms1.size() == 10 );
72  VERIFY( it6 == it5 );
73  VERIFY( *it6 == *it5 );
74
75  const_iterator it7 = ms1.begin();
76  ++it7;
77  ++it7;
78  ++it7;
79  const_iterator it8 = it7;
80  ++it8;
81  const_iterator it9 = ms1.erase(it7);
82  VERIFY( ms1.size() == 9 );
83  VERIFY( it9 == it8 );
84  VERIFY( *it9 == *it8 );
85
86  const_iterator it10 = ms1.begin();
87  ++it10;
88  const_iterator it11 = it10;
89  ++it11;
90  ++it11;
91  ++it11;
92  ++it11;
93  const_iterator it12 = ms1.erase(it10, it11);
94  VERIFY( ms1.size() == 5 );
95  VERIFY( it12 == it11 );
96  VERIFY( *it12 == *it11 );
97
98  iterator it13 = ms1.erase(ms1.begin(), ms1.end());
99  VERIFY( ms1.size() == 0 );
100  VERIFY( it13 == ms1.end() );
101  VERIFY( it13 == ms1.begin() );
102}
103
104int main()
105{
106  test01();
107  return 0;
108}
109