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