]>
Commit | Line | Data |
---|---|---|
f92ab29f | 1 | // 2005-10-08 Paolo Carlini <pcarlini@suse.de> |
3c9b5053 | 2 | // |
a945c346 | 3 | // Copyright (C) 2005-2024 Free Software Foundation, Inc. |
3c9b5053 PC |
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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
3c9b5053 PC |
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 | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
3c9b5053 PC |
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 | // libstdc++/24061 | |
27 | void test01() | |
28 | { | |
3c9b5053 PC |
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; | |
f92ab29f | 34 | |
3c9b5053 PC |
35 | s1.insert("all the love in the world"); |
36 | s1.insert("you know what you are?"); | |
37 | s1.insert("the collector"); | |
38 | s1.insert("the hand that feeds"); | |
39 | s1.insert("love is not enough"); | |
40 | s1.insert("every day is exactly the same"); | |
41 | s1.insert("with teeth"); | |
42 | s1.insert("only"); | |
43 | s1.insert("getting smaller"); | |
44 | s1.insert("sunspots"); | |
45 | VERIFY( s1.size() == 10 ); | |
46 | ||
47 | iterator it1 = s1.begin(); | |
48 | ++it1; | |
49 | iterator it2 = it1; | |
50 | ++it2; | |
51 | iterator it3 = s1.erase(it1); | |
52 | VERIFY( s1.size() == 9 ); | |
53 | VERIFY( it3 == it2 ); | |
54 | VERIFY( *it3 == *it2 ); | |
55 | ||
56 | iterator it4 = s1.begin(); | |
57 | ++it4; | |
58 | ++it4; | |
59 | ++it4; | |
60 | iterator it5 = it4; | |
61 | ++it5; | |
62 | ++it5; | |
63 | iterator it6 = s1.erase(it4, it5); | |
64 | VERIFY( s1.size() == 7 ); | |
65 | VERIFY( it6 == it5 ); | |
66 | VERIFY( *it6 == *it5 ); | |
67 | ||
68 | const_iterator it7 = s1.begin(); | |
69 | ++it7; | |
70 | ++it7; | |
71 | ++it7; | |
72 | const_iterator it8 = it7; | |
73 | ++it8; | |
74 | const_iterator it9 = s1.erase(it7); | |
75 | VERIFY( s1.size() == 6 ); | |
76 | VERIFY( it9 == it8 ); | |
77 | VERIFY( *it9 == *it8 ); | |
78 | ||
79 | const_iterator it10 = s1.begin(); | |
80 | ++it10; | |
81 | const_iterator it11 = it10; | |
82 | ++it11; | |
83 | ++it11; | |
84 | ++it11; | |
85 | ++it11; | |
86 | const_iterator it12 = s1.erase(it10, it11); | |
87 | VERIFY( s1.size() == 2 ); | |
88 | VERIFY( it12 == it11 ); | |
89 | VERIFY( *it12 == *it11 ); | |
90 | VERIFY( ++it12 == s1.end() ); | |
91 | ||
92 | iterator it13 = s1.erase(s1.begin(), s1.end()); | |
93 | VERIFY( s1.size() == 0 ); | |
94 | VERIFY( it13 == s1.end() ); | |
95 | VERIFY( it13 == s1.begin() ); | |
96 | } | |
f92ab29f | 97 | |
3c9b5053 PC |
98 | int main() |
99 | { | |
100 | test01(); | |
101 | return 0; | |
102 | } |