]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/24061-multimap.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_multimap / erase / 24061-multimap.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
3b2524b1
PC
2
3// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com>
4//
a945c346 5// Copyright (C) 2010-2024 Free Software Foundation, Inc.
3b2524b1
PC
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_map>
23#include <string>
24#include <testsuite_hooks.h>
25
26// libstdc++/24061
27void test01()
28{
3b2524b1
PC
29 typedef std::unordered_multimap<std::string, int> Mmap;
30 typedef Mmap::iterator iterator;
31 typedef Mmap::const_iterator const_iterator;
32 typedef Mmap::value_type value_type;
33
34 Mmap mm1;
35
36 mm1.insert(value_type("all the love in the world", 1));
37 mm1.insert(value_type("you know what you are?", 2));
38 mm1.insert(value_type("the collector", 3));
39 mm1.insert(value_type("the hand that feeds", 4));
40 mm1.insert(value_type("love is not enough", 5));
41 mm1.insert(value_type("every day is exactly the same", 6));
42 mm1.insert(value_type("with teeth", 7));
43 mm1.insert(value_type("only", 8));
44 mm1.insert(value_type("getting smaller", 9));
45 mm1.insert(value_type("sunspots", 10));
46
47 mm1.insert(value_type("you know what you are?", 5));
48 mm1.insert(value_type("the collector", 6));
49 mm1.insert(value_type("the hand that feeds", 7));
50 VERIFY( mm1.size() == 13 );
51
52 iterator it1 = mm1.begin();
53 ++it1;
54 iterator it2 = it1;
55 ++it2;
d723ced2 56 iterator it3 = mm1.erase(it1);
3b2524b1 57 VERIFY( mm1.size() == 12 );
d723ced2
PC
58 VERIFY( it3 == it2 );
59 VERIFY( *it3 == *it2 );
3b2524b1
PC
60
61 iterator it4 = mm1.begin();
62 ++it4;
63 ++it4;
64 ++it4;
65 iterator it5 = it4;
66 ++it5;
67 ++it5;
d723ced2 68 iterator it6 = mm1.erase(it4, it5);
3b2524b1 69 VERIFY( mm1.size() == 10 );
d723ced2
PC
70 VERIFY( it6 == it5 );
71 VERIFY( *it6 == *it5 );
3b2524b1
PC
72
73 const_iterator it7 = mm1.begin();
74 ++it7;
75 ++it7;
76 ++it7;
77 const_iterator it8 = it7;
78 ++it8;
d723ced2 79 const_iterator it9 = mm1.erase(it7);
3b2524b1 80 VERIFY( mm1.size() == 9 );
d723ced2
PC
81 VERIFY( it9 == it8 );
82 VERIFY( *it9 == *it8 );
3b2524b1
PC
83
84 const_iterator it10 = mm1.begin();
85 ++it10;
86 const_iterator it11 = it10;
87 ++it11;
88 ++it11;
89 ++it11;
90 ++it11;
d723ced2 91 const_iterator it12 = mm1.erase(it10, it11);
3b2524b1 92 VERIFY( mm1.size() == 5 );
d723ced2
PC
93 VERIFY( it12 == it11 );
94 VERIFY( *it12 == *it11 );
3b2524b1 95
d723ced2 96 iterator it13 = mm1.erase(mm1.begin(), mm1.end());
3b2524b1 97 VERIFY( mm1.size() == 0 );
d723ced2
PC
98 VERIFY( it13 == mm1.end() );
99 VERIFY( it13 == mm1.begin() );
3b2524b1
PC
100}
101
102int main()
103{
104 test01();
105 return 0;
106}