OSDN Git Service

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