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