]>
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-2013 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 3, 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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // hash_map (SGI extension)
25 #include <testsuite_hooks.h>
31 inline size_t hash_string(const char* s
)
40 template<class T
> struct hash
<T
*>
42 size_t operator()(const T
*const & s
) const
43 { return reinterpret_cast<size_t>(s
); }
46 template<> struct hash
<string
>
48 size_t operator()(const string
&s
) const { return hash_string(s
.c_str()); }
51 template<> struct hash
<const string
>
53 size_t operator()(const string
&s
) const { return hash_string(s
.c_str()); }
56 template<class T1
, class T2
> struct hash
<pair
<T1
,T2
> >
60 size_t operator()(const pair
<T1
,T2
> &p
) const {
61 return __fh(p
.first
) ^ __sh(p
.second
);
69 bool test
__attribute__((unused
)) = true;
74 using __gnu_cxx::hash_map
;
76 for (int i
= 0; i
< 10; i
++)
78 hash_map
<string
, int> a
;
79 hash_map
<string
, int> b
;
81 vector
<pair
<string
, int> > contents (Size
);
82 for (int j
= 0; j
< Size
; j
++)
85 for (int k
= 0; k
< 10; k
++)
87 s
+= 'a' + (rand() % 26);
89 contents
[j
] = make_pair(s
,j
);
91 for (int j
= 0; j
< Size
; j
++)
93 a
[contents
[j
].first
] = contents
[j
].second
;
95 b
[contents
[k
].first
] = contents
[k
].second
;