]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/backward/hash_map/1.cc
1 // { dg-options "-Wno-deprecated" }
3 // Copyright (C) 2002, 2005, 2007 Free Software Foundation, Inc.
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)
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.
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,
21 // hash_map (SGI extension)
26 #include <testsuite_hooks.h>
32 inline size_t hash_string(const char* s
)
41 template<class T
> struct hash
<T
*>
43 size_t operator()(const T
*const & s
) const
44 { return reinterpret_cast<size_t>(s
); }
47 template<> struct hash
<string
>
49 size_t operator()(const string
&s
) const { return hash_string(s
.c_str()); }
52 template<> struct hash
<const string
>
54 size_t operator()(const string
&s
) const { return hash_string(s
.c_str()); }
57 template<class T1
, class T2
> struct hash
<pair
<T1
,T2
> >
61 size_t operator()(const pair
<T1
,T2
> &p
) const {
62 return __fh(p
.first
) ^ __sh(p
.second
);
70 bool test
__attribute__((unused
)) = true;
75 using __gnu_cxx::hash_map
;
77 for (int i
= 0; i
< 10; i
++)
79 hash_map
<string
, int> a
;
80 hash_map
<string
, int> b
;
82 vector
<pair
<string
, int> > contents (Size
);
83 for (int j
= 0; j
< Size
; j
++)
86 for (int k
= 0; k
< 10; k
++)
88 s
+= 'a' + (rand() % 26);
90 contents
[j
] = make_pair(s
,j
);
92 for (int j
= 0; j
< Size
; j
++)
94 a
[contents
[j
].first
] = contents
[j
].second
;
96 b
[contents
[k
].first
] = contents
[k
].second
;