re PR target/33755 (Gcc 4.2.2 broken for mips linux kernel builds)
[official-gcc.git] / libstdc++-v3 / src / hash.cc
blob60554dd2a92b571798bac5f460a21aea61826fca
1 // std::hash and std::tr1::hash definitions -*- C++ -*-
3 // Copyright (C) 2007 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 2, or (at your option)
9 // any later version.
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
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 // Boston, MA 02110-1301, USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 #include <cstddef>
31 #include <string>
33 #ifdef __GXX_EXPERIMENTAL_CXX0X__
34 #include <functional>
35 # define _GLIBCXX_BEGIN_NAMESPACE_TR1
36 # define _GLIBCXX_END_NAMESPACE_TR1
37 #else
38 #include <tr1/functional>
39 # define _GLIBCXX_INCLUDE_AS_TR1
40 # define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 {
41 # define _GLIBCXX_END_NAMESPACE_TR1 }
42 #endif
44 namespace std
46 _GLIBCXX_BEGIN_NAMESPACE_TR1
48 template<>
49 size_t
50 hash<string>::operator()(string __s) const
51 { return _Fnv_hash<>::hash(__s.data(), __s.length()); }
53 template<>
54 size_t
55 hash<const string&>::operator()(const string& __s) const
56 { return _Fnv_hash<>::hash(__s.data(), __s.length()); }
58 #ifdef _GLIBCXX_USE_WCHAR_T
59 template<>
60 size_t
61 hash<wstring>::operator()(wstring __s) const
63 const char* __p = reinterpret_cast<const char*>(__s.data());
64 return _Fnv_hash<>::hash(__p, __s.length() * sizeof(wchar_t));
67 template<>
68 size_t
69 hash<const wstring&>::operator()(const wstring& __s) const
71 const char* __p = reinterpret_cast<const char*>(__s.data());
72 return _Fnv_hash<>::hash(__p, __s.length() * sizeof(wchar_t));
74 #endif
76 _GLIBCXX_END_NAMESPACE_TR1