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