]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/tr1/6_containers/unordered_multimap/erase/1.cc
re PR libstdc++/25896 ([DR 526] hash_map::erase, unordered_map::erase fail if key...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / tr1 / 6_containers / unordered_multimap / erase / 1.cc
CommitLineData
c0c424e4
PC
1// 2007-02-22 Paolo Carlini <pcarlini@suse.de>
2//
3// Copyright (C) 2007 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.6 Class template unordered_multimap
22
23#include <tr1/unordered_map>
24#include <string>
25#include <testsuite_hooks.h>
26
27// In the occasion of libstdc++/25896
28void test01()
29{
30 bool test __attribute__((unused)) = true;
31
32 typedef std::tr1::unordered_multimap<std::string, int> Mmap;
33 typedef Mmap::iterator iterator;
34 typedef Mmap::const_iterator const_iterator;
35 typedef Mmap::value_type value_type;
36
37 Mmap mm1;
38
39 mm1.insert(value_type("because to why", 1));
40 mm1.insert(value_type("the stockholm syndrome", 2));
41 mm1.insert(value_type("a cereous night", 3));
42 mm1.insert(value_type("eeilo", 4));
43 mm1.insert(value_type("protean", 5));
44 mm1.insert(value_type("the way you are when", 6));
45 mm1.insert(value_type("tillsammans", 7));
46 mm1.insert(value_type("umbra/penumbra", 8));
47 mm1.insert(value_type("belonging (no longer mix)", 9));
48 mm1.insert(value_type("one line behind", 10));
49 VERIFY( mm1.size() == 10 );
50
51 VERIFY( mm1.erase("eeilo") == 1 );
52 VERIFY( mm1.size() == 9 );
53 iterator it1 = mm1.find("eeilo");
54 VERIFY( it1 == mm1.end() );
55
56 VERIFY( mm1.erase("tillsammans") == 1 );
57 VERIFY( mm1.size() == 8 );
58 iterator it2 = mm1.find("tillsammans");
59 VERIFY( it2 == mm1.end() );
60
61 // Must work (see DR 526)
62 iterator it3 = mm1.find("belonging (no longer mix)");
63 VERIFY( it3 != mm1.end() );
64 VERIFY( mm1.erase(it3->first) == 1 );
65 VERIFY( mm1.size() == 7 );
66 it3 = mm1.find("belonging (no longer mix)");
67 VERIFY( it3 == mm1.end() );
68
69 VERIFY( !mm1.erase("abra") );
70 VERIFY( mm1.size() == 7 );
71
72 VERIFY( !mm1.erase("eeilo") );
73 VERIFY( mm1.size() == 7 );
74
75 VERIFY( mm1.erase("because to why") == 1 );
76 VERIFY( mm1.size() == 6 );
77 iterator it4 = mm1.find("because to why");
78 VERIFY( it4 == mm1.end() );
79
80 iterator it5 = mm1.find("umbra/penumbra");
81 iterator it6 = mm1.find("one line behind");
82 VERIFY( it5 != mm1.end() );
83 VERIFY( it6 != mm1.end() );
84
85 VERIFY( mm1.find("the stockholm syndrome") != mm1.end() );
86 VERIFY( mm1.find("a cereous night") != mm1.end() );
87 VERIFY( mm1.find("the way you are when") != mm1.end() );
88 VERIFY( mm1.find("a cereous night") != mm1.end() );
89
90 VERIFY( mm1.erase(it5->first) == 1 );
91 VERIFY( mm1.size() == 5 );
92 it5 = mm1.find("umbra/penumbra");
93 VERIFY( it5 == mm1.end() );
94
95 VERIFY( mm1.erase(it6->first) == 1 );
96 VERIFY( mm1.size() == 4 );
97 it6 = mm1.find("one line behind");
98 VERIFY( it6 == mm1.end() );
99
100 iterator it7 = mm1.begin();
101 iterator it8 = it7;
102 ++it8;
103 iterator it9 = it8;
104 ++it9;
105
106 VERIFY( mm1.erase(it8->first) == 1 );
107 VERIFY( mm1.size() == 3 );
108 VERIFY( ++it7 == it9 );
109
110 iterator it10 = it9;
111 ++it10;
112 iterator it11 = it10;
113
114 VERIFY( mm1.erase(it9->first) == 1 );
115 VERIFY( mm1.size() == 2 );
116 VERIFY( ++it10 == mm1.end() );
117
118 VERIFY( mm1.erase(mm1.begin()) != mm1.end() );
119 VERIFY( mm1.size() == 1 );
120 VERIFY( mm1.begin() == it11 );
121
122 VERIFY( mm1.erase(mm1.begin()->first) == 1 );
123 VERIFY( mm1.size() == 0 );
124 VERIFY( mm1.begin() == mm1.end() );
125}
126
127int main()
128{
129 test01();
130 return 0;
131}