1// { dg-options "-std=gnu++11" }
2
3// 2010-02-10  Paolo Carlini  <paolo.carlini@oracle.com>
4//
5// Copyright (C) 2010-2015 Free Software Foundation, Inc.
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{
29  bool test __attribute__((unused)) = true;
30
31  typedef std::unordered_map<std::string, int> Map;
32  typedef Map::iterator       iterator;
33  typedef Map::const_iterator const_iterator;
34  typedef Map::value_type     value_type;
35
36  Map m1;
37
38  m1.insert(value_type("all the love in the world", 1));
39  m1.insert(value_type("you know what you are?", 2));
40  m1.insert(value_type("the collector", 3));
41  m1.insert(value_type("the hand that feeds", 4));
42  m1.insert(value_type("love is not enough", 5));
43  m1.insert(value_type("every day is exactly the same", 6));
44  m1.insert(value_type("with teeth", 7));
45  m1.insert(value_type("only", 8));
46  m1.insert(value_type("getting smaller", 9));
47  m1.insert(value_type("sunspots", 10));
48  VERIFY( m1.size() == 10 );
49
50  iterator it1 = m1.begin();
51  ++it1;
52  iterator it2 = it1;
53  ++it2;
54  iterator it3 = m1.erase(it1);
55  VERIFY( m1.size() == 9 );
56  VERIFY( it3 == it2 );
57  VERIFY( *it3 == *it2 );
58
59  iterator it4 = m1.begin();
60  ++it4;
61  ++it4;
62  ++it4;
63  iterator it5 = it4;
64  ++it5;
65  ++it5;
66  iterator it6 = m1.erase(it4, it5);
67  VERIFY( m1.size() == 7 );
68  VERIFY( it6 == it5 );
69  VERIFY( *it6 == *it5 );
70
71  const_iterator it7 = m1.begin();
72  ++it7;
73  ++it7;
74  ++it7;
75  const_iterator it8 = it7;
76  ++it8;
77  const_iterator it9 = m1.erase(it7);
78  VERIFY( m1.size() == 6 );
79  VERIFY( it9 == it8 );
80  VERIFY( *it9 == *it8 );
81
82  const_iterator it10 = m1.begin();
83  ++it10;
84  const_iterator it11 = it10;
85  ++it11;
86  ++it11;
87  ++it11;
88  ++it11;
89  const_iterator it12 = m1.erase(it10, it11);
90  VERIFY( m1.size() == 2 );
91  VERIFY( it12 == it11 );
92  VERIFY( *it12 == *it11 );
93  VERIFY( ++it12 == m1.end() );
94
95  iterator it13 = m1.erase(m1.begin(), m1.end());
96  VERIFY( m1.size() == 0 );
97  VERIFY( it13 == it12 );
98  VERIFY( it13 == m1.begin() );
99}
100
101int main()
102{
103  test01();
104  return 0;
105}
106