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