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