| 1 |
// 2005-10-08 Paolo Carlini <[email protected]> |
| 2 |
// |
| 3 |
// Copyright (C) 2005-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.4 Class template unordered_map |
| 21 |
|
| 22 |
#include <tr1/unordered_map> |
| 23 |
#include <string> |
| 24 |
#include <testsuite_hooks.h> |
| 25 |
|
| 26 |
// libstdc++/24061 |
| 27 |
void test01() |
| 28 |
{ |
| 29 |
typedef std::tr1::unordered_map<std::string, int> Map; |
| 30 |
typedef Map::iterator iterator; |
| 31 |
typedef Map::const_iterator const_iterator; |
| 32 |
typedef Map::value_type value_type; |
| 33 |
|
| 34 |
Map m1; |
| 35 |
|
| 36 |
m1.insert(value_type("all the love in the world", 1)); |
| 37 |
m1.insert(value_type("you know what you are?", 2)); |
| 38 |
m1.insert(value_type("the collector", 3)); |
| 39 |
m1.insert(value_type("the hand that feeds", 4)); |
| 40 |
m1.insert(value_type("love is not enough", 5)); |
| 41 |
m1.insert(value_type("every day is exactly the same", 6)); |
| 42 |
m1.insert(value_type("with teeth", 7)); |
| 43 |
m1.insert(value_type("only", 8)); |
| 44 |
m1.insert(value_type("getting smaller", 9)); |
| 45 |
m1.insert(value_type("sunspots", 10)); |
| 46 |
VERIFY( m1.size() == 10 ); |
| 47 |
|
| 48 |
iterator it1 = m1.begin(); |
| 49 |
++it1; |
| 50 |
iterator it2 = it1; |
| 51 |
++it2; |
| 52 |
iterator it3 = m1.erase(it1); |
| 53 |
VERIFY( m1.size() == 9 ); |
| 54 |
VERIFY( it3 == it2 ); |
| 55 |
VERIFY( *it3 == *it2 ); |
| 56 |
|
| 57 |
iterator it4 = m1.begin(); |
| 58 |
++it4; |
| 59 |
++it4; |
| 60 |
++it4; |
| 61 |
iterator it5 = it4; |
| 62 |
++it5; |
| 63 |
++it5; |
| 64 |
iterator it6 = m1.erase(it4, it5); |
| 65 |
VERIFY( m1.size() == 7 ); |
| 66 |
VERIFY( it6 == it5 ); |
| 67 |
VERIFY( *it6 == *it5 ); |
| 68 |
|
| 69 |
const_iterator it7 = m1.begin(); |
| 70 |
++it7; |
| 71 |
++it7; |
| 72 |
++it7; |
| 73 |
const_iterator it8 = it7; |
| 74 |
++it8; |
| 75 |
const_iterator it9 = m1.erase(it7); |
| 76 |
VERIFY( m1.size() == 6 ); |
| 77 |
VERIFY( it9 == it8 ); |
| 78 |
VERIFY( *it9 == *it8 ); |
| 79 |
|
| 80 |
const_iterator it10 = m1.begin(); |
| 81 |
++it10; |
| 82 |
const_iterator it11 = it10; |
| 83 |
++it11; |
| 84 |
++it11; |
| 85 |
++it11; |
| 86 |
++it11; |
| 87 |
const_iterator it12 = m1.erase(it10, it11); |
| 88 |
VERIFY( m1.size() == 2 ); |
| 89 |
VERIFY( it12 == it11 ); |
| 90 |
VERIFY( *it12 == *it11 ); |
| 91 |
VERIFY( ++it12 == m1.end() ); |
| 92 |
|
| 93 |
iterator it13 = m1.erase(m1.begin(), m1.end()); |
| 94 |
VERIFY( m1.size() == 0 ); |
| 95 |
VERIFY( it13 == it12 ); |
| 96 |
VERIFY( it13 == m1.begin() ); |
| 97 |
} |
| 98 |
|
| 99 |
int main() |
| 100 |
{ |
| 101 |
test01(); |
| 102 |
return 0; |
| 103 |
} |