1// 2005-10-08  Paolo Carlini  <pcarlini@suse.de>
2//
3// Copyright (C) 2005 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 2, 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 COPYING.  If not, write to the Free
18// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19// USA.
20
21// 6.3.4.4  Class template unordered_map
22
23#include <tr1/unordered_map>
24#include <string>
25#include <testsuite_hooks.h>
26
27// libstdc++/24061
28void test01()
29{
30  bool test __attribute__((unused)) = true;
31
32  typedef std::tr1::unordered_map<std::string, int> Map;
33  typedef Map::iterator       iterator;
34  typedef Map::const_iterator const_iterator;
35  typedef Map::value_type     value_type;
36
37  Map m1;
38
39  m1.insert(value_type("all the love in the world", 1));
40  m1.insert(value_type("you know what you are?", 2));
41  m1.insert(value_type("the collector", 3));
42  m1.insert(value_type("the hand that feeds", 4));
43  m1.insert(value_type("love is not enough", 5));
44  m1.insert(value_type("every day is exactly the same", 6));
45  m1.insert(value_type("with teeth", 7));
46  m1.insert(value_type("only", 8));
47  m1.insert(value_type("getting smaller", 9));
48  m1.insert(value_type("sunspots", 10));
49  VERIFY( m1.size() == 10 );
50
51  iterator it1 = m1.begin();
52  ++it1;
53  iterator it2 = it1;
54  ++it2;
55  iterator it3 = m1.erase(it1);
56  VERIFY( m1.size() == 9 );
57  VERIFY( it3 == it2 );
58  VERIFY( *it3 == *it2 );
59
60  iterator it4 = m1.begin();
61  ++it4;
62  ++it4;
63  ++it4;
64  iterator it5 = it4;
65  ++it5;
66  ++it5;
67  iterator it6 = m1.erase(it4, it5);
68  VERIFY( m1.size() == 7 );
69  VERIFY( it6 == it5 );
70  VERIFY( *it6 == *it5 );
71
72  const_iterator it7 = m1.begin();
73  ++it7;
74  ++it7;
75  ++it7;
76  const_iterator it8 = it7;
77  ++it8;
78  const_iterator it9 = m1.erase(it7);
79  VERIFY( m1.size() == 6 );
80  VERIFY( it9 == it8 );
81  VERIFY( *it9 == *it8 );
82
83  const_iterator it10 = m1.begin();
84  ++it10;
85  const_iterator it11 = it10;
86  ++it11;
87  ++it11;
88  ++it11;
89  ++it11;
90  const_iterator it12 = m1.erase(it10, it11);
91  VERIFY( m1.size() == 2 );
92  VERIFY( it12 == it11 );
93  VERIFY( *it12 == *it11 );
94  VERIFY( ++it12 == m1.end() );
95
96  iterator it13 = m1.erase(m1.begin(), m1.end());
97  VERIFY( m1.size() == 0 );
98  VERIFY( it13 == it12 );
99  VERIFY( it13 == m1.begin() );
100}
101
102int main()
103{
104  test01();
105  return 0;
106}
107