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