OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc3/] [libstdc++-v3/] [testsuite/] [backward/] [hash_set/] [25896.cc] - Blame information for rev 516

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// { dg-options "-Wno-deprecated" }
2
//
3
// Copyright (C) 2009 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 3, 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 COPYING3.  If not see
18
// <http://www.gnu.org/licenses/>.
19
 
20
// This is a copy of tr1/6_containers/unordered_set/erase/1.cc, using
21
// hash_set instead of unordered_set.
22
 
23
#include <hash_set>
24
#include <string>
25
#include <testsuite_hooks.h>
26
 
27
namespace __gnu_cxx
28
{
29
  using std::string;
30
 
31
  inline size_t hash_string(const char* s)
32
  {
33
    unsigned long h;
34
    for (h=0; *s; ++s) {
35
      h = 5*h + *s;
36
    }
37
    return size_t(h);
38
  }
39
 
40
  template<class T> struct hash<T *>
41
  {
42
    size_t operator()(const T *const & s) const
43
      { return reinterpret_cast<size_t>(s); }
44
  };
45
 
46
  template<> struct hash<string>
47
  {
48
    size_t operator()(const string &s) const { return hash_string(s.c_str()); }
49
  };
50
 
51
  template<> struct hash<const string>
52
  {
53
    size_t operator()(const string &s) const { return hash_string(s.c_str()); }
54
  };
55
}
56
 
57
void test01()
58
{
59
  bool test __attribute__((unused)) = true;
60
 
61
  typedef __gnu_cxx::hash_set<std::string> Set;
62
  typedef Set::iterator       iterator;
63
  typedef Set::const_iterator const_iterator;
64
 
65
  Set s1;
66
 
67
  s1.insert("because to why");
68
  s1.insert("the stockholm syndrome");
69
  s1.insert("a cereous night");
70
  s1.insert("eeilo");
71
  s1.insert("protean");
72
  s1.insert("the way you are when");
73
  s1.insert("tillsammans");
74
  s1.insert("umbra/penumbra");
75
  s1.insert("belonging (no longer mix)");
76
  s1.insert("one line behind");
77
  VERIFY( s1.size() == 10 );
78
 
79
  VERIFY( s1.erase("eeilo") == 1 );
80
  VERIFY( s1.size() == 9 );
81
  iterator it1 = s1.find("eeilo");
82
  VERIFY( it1 == s1.end() );
83
 
84
  VERIFY( s1.erase("tillsammans") == 1 );
85
  VERIFY( s1.size() == 8 );
86
  iterator it2 = s1.find("tillsammans");
87
  VERIFY( it2 == s1.end() );
88
 
89
  // Must work (see DR 526)
90
  iterator it3 = s1.find("belonging (no longer mix)");
91
  VERIFY( it3 != s1.end() );
92
  VERIFY( s1.erase(*it3) == 1 );
93
  VERIFY( s1.size() == 7 );
94
  it3 = s1.find("belonging (no longer mix)");
95
  VERIFY( it3 == s1.end() );
96
 
97
  VERIFY( !s1.erase("abra") );
98
  VERIFY( s1.size() == 7 );
99
 
100
  VERIFY( !s1.erase("eeilo") );
101
  VERIFY( s1.size() == 7 );
102
 
103
  VERIFY( s1.erase("because to why") == 1 );
104
  VERIFY( s1.size() == 6 );
105
  iterator it4 = s1.find("because to why");
106
  VERIFY( it4 == s1.end() );
107
 
108
  iterator it5 = s1.find("umbra/penumbra");
109
  iterator it6 = s1.find("one line behind");
110
  VERIFY( it5 != s1.end() );
111
  VERIFY( it6 != s1.end() );
112
 
113
  VERIFY( s1.find("the stockholm syndrome") != s1.end() );
114
  VERIFY( s1.find("a cereous night") != s1.end() );
115
  VERIFY( s1.find("the way you are when") != s1.end() );
116
  VERIFY( s1.find("a cereous night") != s1.end() );
117
 
118
  VERIFY( s1.erase(*it5) == 1 );
119
  VERIFY( s1.size() == 5 );
120
  it5 = s1.find("umbra/penumbra");
121
  VERIFY( it5 == s1.end() );
122
 
123
  VERIFY( s1.erase(*it6) == 1 );
124
  VERIFY( s1.size() == 4 );
125
  it6 = s1.find("one line behind");
126
  VERIFY( it6 == s1.end() );
127
 
128
  iterator it7 = s1.begin();
129
  iterator it8 = it7;
130
  ++it8;
131
  iterator it9 = it8;
132
  ++it9;
133
 
134
  VERIFY( s1.erase(*it8) == 1 );
135
  VERIFY( s1.size() == 3 );
136
  VERIFY( ++it7 == it9 );
137
 
138
  iterator it10 = it9;
139
  ++it10;
140
  iterator it11 = it10;
141
 
142
  VERIFY( s1.erase(*it9) == 1 );
143
  VERIFY( s1.size() == 2 );
144
  VERIFY( ++it10 == s1.end() );
145
 
146
  s1.erase(s1.begin());
147
  VERIFY( s1.size() == 1 );
148
  VERIFY( s1.begin() == it11 );
149
 
150
  VERIFY( s1.erase(*s1.begin()) == 1 );
151
  VERIFY( s1.size() == 0 );
152
  VERIFY( s1.begin() == s1.end() );
153
}
154
 
155
int main()
156
{
157
  test01();
158
  return 0;
159
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.