1 // { dg-do run { target c++11 } }
3 // 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com>
5 // Copyright (C) 2010-2025 Free Software Foundation, Inc.
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)
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.
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/>.
22 #include <unordered_map>
24 #include <testsuite_hooks.h>
29 typedef std::unordered_map
<std::string
, int> Map
;
30 typedef Map::iterator iterator
;
31 typedef Map::const_iterator const_iterator
;
32 typedef Map::value_type value_type
;
36 m1
.insert(value_type("all the love in the world", 1));
37 m1
.insert(value_type("you know what you are?", 2));
38 m1
.insert(value_type("the collector", 3));
39 m1
.insert(value_type("the hand that feeds", 4));
40 m1
.insert(value_type("love is not enough", 5));
41 m1
.insert(value_type("every day is exactly the same", 6));
42 m1
.insert(value_type("with teeth", 7));
43 m1
.insert(value_type("only", 8));
44 m1
.insert(value_type("getting smaller", 9));
45 m1
.insert(value_type("sunspots", 10));
46 VERIFY( m1
.size() == 10 );
48 iterator it1
= m1
.begin();
52 iterator it3
= m1
.erase(it1
);
53 VERIFY( m1
.size() == 9 );
55 VERIFY( *it3
== *it2
);
57 iterator it4
= m1
.begin();
64 iterator it6
= m1
.erase(it4
, it5
);
65 VERIFY( m1
.size() == 7 );
67 VERIFY( *it6
== *it5
);
69 const_iterator it7
= m1
.begin();
73 const_iterator it8
= it7
;
75 const_iterator it9
= m1
.erase(it7
);
76 VERIFY( m1
.size() == 6 );
78 VERIFY( *it9
== *it8
);
80 const_iterator it10
= m1
.begin();
82 const_iterator it11
= it10
;
87 const_iterator it12
= m1
.erase(it10
, it11
);
88 VERIFY( m1
.size() == 2 );
89 VERIFY( it12
== it11
);
90 VERIFY( *it12
== *it11
);
91 VERIFY( ++it12
== m1
.end() );
93 iterator it13
= m1
.erase(m1
.begin(), m1
.end());
94 VERIFY( m1
.size() == 0 );
95 VERIFY( it13
== it12
);
96 VERIFY( it13
== m1
.begin() );