Chris@16
|
1
|
Chris@16
|
2 // Copyright 2005-2009 Daniel James.
|
Chris@16
|
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5
|
Chris@16
|
6 // Based on Peter Dimov's proposal
|
Chris@16
|
7 // http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf
|
Chris@16
|
8 // issue 6.18.
|
Chris@16
|
9
|
Chris@16
|
10 #if !defined(BOOST_FUNCTIONAL_HASH_HASH_HPP)
|
Chris@16
|
11 #define BOOST_FUNCTIONAL_HASH_HASH_HPP
|
Chris@16
|
12
|
Chris@16
|
13 #include <boost/functional/hash/hash_fwd.hpp>
|
Chris@16
|
14 #include <functional>
|
Chris@16
|
15 #include <boost/functional/hash/detail/hash_float.hpp>
|
Chris@16
|
16 #include <string>
|
Chris@16
|
17 #include <boost/limits.hpp>
|
Chris@16
|
18 #include <boost/type_traits/is_enum.hpp>
|
Chris@16
|
19 #include <boost/type_traits/is_integral.hpp>
|
Chris@16
|
20 #include <boost/utility/enable_if.hpp>
|
Chris@16
|
21
|
Chris@16
|
22 #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
Chris@16
|
23 #include <boost/type_traits/is_pointer.hpp>
|
Chris@16
|
24 #endif
|
Chris@16
|
25
|
Chris@16
|
26 #if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX)
|
Chris@16
|
27 #include <typeindex>
|
Chris@16
|
28 #endif
|
Chris@16
|
29
|
Chris@16
|
30 #if defined(BOOST_MSVC)
|
Chris@16
|
31 #pragma warning(push)
|
Chris@16
|
32 #pragma warning(disable:6295) // Ill-defined for-loop : 'unsigned int' values
|
Chris@16
|
33 // are always of range '0' to '4294967295'.
|
Chris@16
|
34 // Loop executes infinitely.
|
Chris@16
|
35 #endif
|
Chris@16
|
36
|
Chris@16
|
37 #if BOOST_WORKAROUND(__GNUC__, < 3) \
|
Chris@16
|
38 && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
|
Chris@16
|
39 #define BOOST_HASH_CHAR_TRAITS string_char_traits
|
Chris@16
|
40 #else
|
Chris@16
|
41 #define BOOST_HASH_CHAR_TRAITS char_traits
|
Chris@16
|
42 #endif
|
Chris@16
|
43
|
Chris@16
|
44 namespace boost
|
Chris@16
|
45 {
|
Chris@16
|
46 namespace hash_detail
|
Chris@16
|
47 {
|
Chris@16
|
48 struct enable_hash_value { typedef std::size_t type; };
|
Chris@16
|
49
|
Chris@16
|
50 template <typename T> struct basic_numbers {};
|
Chris@16
|
51 template <typename T> struct long_numbers;
|
Chris@16
|
52 template <typename T> struct ulong_numbers;
|
Chris@16
|
53 template <typename T> struct float_numbers {};
|
Chris@16
|
54
|
Chris@16
|
55 template <> struct basic_numbers<bool> :
|
Chris@16
|
56 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
57 template <> struct basic_numbers<char> :
|
Chris@16
|
58 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
59 template <> struct basic_numbers<unsigned char> :
|
Chris@16
|
60 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
61 template <> struct basic_numbers<signed char> :
|
Chris@16
|
62 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
63 template <> struct basic_numbers<short> :
|
Chris@16
|
64 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
65 template <> struct basic_numbers<unsigned short> :
|
Chris@16
|
66 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
67 template <> struct basic_numbers<int> :
|
Chris@16
|
68 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
69 template <> struct basic_numbers<unsigned int> :
|
Chris@16
|
70 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
71 template <> struct basic_numbers<long> :
|
Chris@16
|
72 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
73 template <> struct basic_numbers<unsigned long> :
|
Chris@16
|
74 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
75
|
Chris@16
|
76 #if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
Chris@16
|
77 template <> struct basic_numbers<wchar_t> :
|
Chris@16
|
78 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
79 #endif
|
Chris@16
|
80
|
Chris@16
|
81 // long_numbers is defined like this to allow for separate
|
Chris@16
|
82 // specialization for long_long and int128_type, in case
|
Chris@16
|
83 // they conflict.
|
Chris@16
|
84 template <typename T> struct long_numbers2 {};
|
Chris@16
|
85 template <typename T> struct ulong_numbers2 {};
|
Chris@16
|
86 template <typename T> struct long_numbers : long_numbers2<T> {};
|
Chris@16
|
87 template <typename T> struct ulong_numbers : ulong_numbers2<T> {};
|
Chris@16
|
88
|
Chris@16
|
89 #if !defined(BOOST_NO_LONG_LONG)
|
Chris@16
|
90 template <> struct long_numbers<boost::long_long_type> :
|
Chris@16
|
91 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
92 template <> struct ulong_numbers<boost::ulong_long_type> :
|
Chris@16
|
93 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
94 #endif
|
Chris@16
|
95
|
Chris@16
|
96 #if defined(BOOST_HAS_INT128)
|
Chris@16
|
97 template <> struct long_numbers2<boost::int128_type> :
|
Chris@16
|
98 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
99 template <> struct ulong_numbers2<boost::uint128_type> :
|
Chris@16
|
100 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
101 #endif
|
Chris@16
|
102
|
Chris@16
|
103 template <> struct float_numbers<float> :
|
Chris@16
|
104 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
105 template <> struct float_numbers<double> :
|
Chris@16
|
106 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
107 template <> struct float_numbers<long double> :
|
Chris@16
|
108 boost::hash_detail::enable_hash_value {};
|
Chris@16
|
109 }
|
Chris@16
|
110
|
Chris@16
|
111 template <typename T>
|
Chris@16
|
112 typename boost::hash_detail::basic_numbers<T>::type hash_value(T);
|
Chris@16
|
113 template <typename T>
|
Chris@16
|
114 typename boost::hash_detail::long_numbers<T>::type hash_value(T);
|
Chris@16
|
115 template <typename T>
|
Chris@16
|
116 typename boost::hash_detail::ulong_numbers<T>::type hash_value(T);
|
Chris@16
|
117
|
Chris@16
|
118 template <typename T>
|
Chris@16
|
119 typename boost::enable_if<boost::is_enum<T>, std::size_t>::type
|
Chris@16
|
120 hash_value(T);
|
Chris@16
|
121
|
Chris@16
|
122 #if !BOOST_WORKAROUND(__DMC__, <= 0x848)
|
Chris@16
|
123 template <class T> std::size_t hash_value(T* const&);
|
Chris@16
|
124 #else
|
Chris@16
|
125 template <class T> std::size_t hash_value(T*);
|
Chris@16
|
126 #endif
|
Chris@16
|
127
|
Chris@16
|
128 #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
Chris@16
|
129 template< class T, unsigned N >
|
Chris@16
|
130 std::size_t hash_value(const T (&x)[N]);
|
Chris@16
|
131
|
Chris@16
|
132 template< class T, unsigned N >
|
Chris@16
|
133 std::size_t hash_value(T (&x)[N]);
|
Chris@16
|
134 #endif
|
Chris@16
|
135
|
Chris@16
|
136 template <class Ch, class A>
|
Chris@16
|
137 std::size_t hash_value(
|
Chris@16
|
138 std::basic_string<Ch, std::BOOST_HASH_CHAR_TRAITS<Ch>, A> const&);
|
Chris@16
|
139
|
Chris@16
|
140 template <typename T>
|
Chris@16
|
141 typename boost::hash_detail::float_numbers<T>::type hash_value(T);
|
Chris@16
|
142
|
Chris@16
|
143 #if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX)
|
Chris@16
|
144 std::size_t hash_value(std::type_index);
|
Chris@16
|
145 #endif
|
Chris@16
|
146
|
Chris@16
|
147 // Implementation
|
Chris@16
|
148
|
Chris@16
|
149 namespace hash_detail
|
Chris@16
|
150 {
|
Chris@16
|
151 template <class T>
|
Chris@16
|
152 inline std::size_t hash_value_signed(T val)
|
Chris@16
|
153 {
|
Chris@16
|
154 const int size_t_bits = std::numeric_limits<std::size_t>::digits;
|
Chris@16
|
155 // ceiling(std::numeric_limits<T>::digits / size_t_bits) - 1
|
Chris@16
|
156 const int length = (std::numeric_limits<T>::digits - 1)
|
Chris@16
|
157 / size_t_bits;
|
Chris@16
|
158
|
Chris@16
|
159 std::size_t seed = 0;
|
Chris@16
|
160 T positive = val < 0 ? -1 - val : val;
|
Chris@16
|
161
|
Chris@16
|
162 // Hopefully, this loop can be unrolled.
|
Chris@16
|
163 for(unsigned int i = length * size_t_bits; i > 0; i -= size_t_bits)
|
Chris@16
|
164 {
|
Chris@16
|
165 seed ^= (std::size_t) (positive >> i) + (seed<<6) + (seed>>2);
|
Chris@16
|
166 }
|
Chris@16
|
167 seed ^= (std::size_t) val + (seed<<6) + (seed>>2);
|
Chris@16
|
168
|
Chris@16
|
169 return seed;
|
Chris@16
|
170 }
|
Chris@16
|
171
|
Chris@16
|
172 template <class T>
|
Chris@16
|
173 inline std::size_t hash_value_unsigned(T val)
|
Chris@16
|
174 {
|
Chris@16
|
175 const int size_t_bits = std::numeric_limits<std::size_t>::digits;
|
Chris@16
|
176 // ceiling(std::numeric_limits<T>::digits / size_t_bits) - 1
|
Chris@16
|
177 const int length = (std::numeric_limits<T>::digits - 1)
|
Chris@16
|
178 / size_t_bits;
|
Chris@16
|
179
|
Chris@16
|
180 std::size_t seed = 0;
|
Chris@16
|
181
|
Chris@16
|
182 // Hopefully, this loop can be unrolled.
|
Chris@16
|
183 for(unsigned int i = length * size_t_bits; i > 0; i -= size_t_bits)
|
Chris@16
|
184 {
|
Chris@16
|
185 seed ^= (std::size_t) (val >> i) + (seed<<6) + (seed>>2);
|
Chris@16
|
186 }
|
Chris@16
|
187 seed ^= (std::size_t) val + (seed<<6) + (seed>>2);
|
Chris@16
|
188
|
Chris@16
|
189 return seed;
|
Chris@16
|
190 }
|
Chris@16
|
191 }
|
Chris@16
|
192
|
Chris@16
|
193 template <typename T>
|
Chris@16
|
194 typename boost::hash_detail::basic_numbers<T>::type hash_value(T v)
|
Chris@16
|
195 {
|
Chris@16
|
196 return static_cast<std::size_t>(v);
|
Chris@16
|
197 }
|
Chris@16
|
198
|
Chris@16
|
199 template <typename T>
|
Chris@16
|
200 typename boost::hash_detail::long_numbers<T>::type hash_value(T v)
|
Chris@16
|
201 {
|
Chris@16
|
202 return hash_detail::hash_value_signed(v);
|
Chris@16
|
203 }
|
Chris@16
|
204
|
Chris@16
|
205 template <typename T>
|
Chris@16
|
206 typename boost::hash_detail::ulong_numbers<T>::type hash_value(T v)
|
Chris@16
|
207 {
|
Chris@16
|
208 return hash_detail::hash_value_unsigned(v);
|
Chris@16
|
209 }
|
Chris@16
|
210
|
Chris@16
|
211 template <typename T>
|
Chris@16
|
212 typename boost::enable_if<boost::is_enum<T>, std::size_t>::type
|
Chris@16
|
213 hash_value(T v)
|
Chris@16
|
214 {
|
Chris@16
|
215 return static_cast<std::size_t>(v);
|
Chris@16
|
216 }
|
Chris@16
|
217
|
Chris@16
|
218 // Implementation by Alberto Barbati and Dave Harris.
|
Chris@16
|
219 #if !BOOST_WORKAROUND(__DMC__, <= 0x848)
|
Chris@16
|
220 template <class T> std::size_t hash_value(T* const& v)
|
Chris@16
|
221 #else
|
Chris@16
|
222 template <class T> std::size_t hash_value(T* v)
|
Chris@16
|
223 #endif
|
Chris@16
|
224 {
|
Chris@16
|
225 #if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
|
Chris@16
|
226 // for some reason ptrdiff_t on OpenVMS compiler with
|
Chris@16
|
227 // 64 bit is not 64 bit !!!
|
Chris@16
|
228 std::size_t x = static_cast<std::size_t>(
|
Chris@16
|
229 reinterpret_cast<long long int>(v));
|
Chris@16
|
230 #else
|
Chris@16
|
231 std::size_t x = static_cast<std::size_t>(
|
Chris@16
|
232 reinterpret_cast<std::ptrdiff_t>(v));
|
Chris@16
|
233 #endif
|
Chris@16
|
234 return x + (x >> 3);
|
Chris@16
|
235 }
|
Chris@16
|
236
|
Chris@16
|
237 #if defined(BOOST_MSVC)
|
Chris@16
|
238 #pragma warning(push)
|
Chris@16
|
239 #if BOOST_MSVC <= 1400
|
Chris@16
|
240 #pragma warning(disable:4267) // 'argument' : conversion from 'size_t' to
|
Chris@16
|
241 // 'unsigned int', possible loss of data
|
Chris@16
|
242 // A misguided attempt to detect 64-bit
|
Chris@16
|
243 // incompatability.
|
Chris@16
|
244 #endif
|
Chris@16
|
245 #endif
|
Chris@16
|
246
|
Chris@16
|
247 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
Chris@16
|
248 template <class T>
|
Chris@16
|
249 inline void hash_combine(std::size_t& seed, T& v)
|
Chris@16
|
250 #else
|
Chris@16
|
251 template <class T>
|
Chris@16
|
252 inline void hash_combine(std::size_t& seed, T const& v)
|
Chris@16
|
253 #endif
|
Chris@16
|
254 {
|
Chris@16
|
255 boost::hash<T> hasher;
|
Chris@16
|
256 seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
|
Chris@16
|
257 }
|
Chris@16
|
258
|
Chris@16
|
259 #if defined(BOOST_MSVC)
|
Chris@16
|
260 #pragma warning(pop)
|
Chris@16
|
261 #endif
|
Chris@16
|
262
|
Chris@16
|
263 template <class It>
|
Chris@16
|
264 inline std::size_t hash_range(It first, It last)
|
Chris@16
|
265 {
|
Chris@16
|
266 std::size_t seed = 0;
|
Chris@16
|
267
|
Chris@16
|
268 for(; first != last; ++first)
|
Chris@16
|
269 {
|
Chris@16
|
270 hash_combine(seed, *first);
|
Chris@16
|
271 }
|
Chris@16
|
272
|
Chris@16
|
273 return seed;
|
Chris@16
|
274 }
|
Chris@16
|
275
|
Chris@16
|
276 template <class It>
|
Chris@16
|
277 inline void hash_range(std::size_t& seed, It first, It last)
|
Chris@16
|
278 {
|
Chris@16
|
279 for(; first != last; ++first)
|
Chris@16
|
280 {
|
Chris@16
|
281 hash_combine(seed, *first);
|
Chris@16
|
282 }
|
Chris@16
|
283 }
|
Chris@16
|
284
|
Chris@16
|
285 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
Chris@16
|
286 template <class T>
|
Chris@16
|
287 inline std::size_t hash_range(T* first, T* last)
|
Chris@16
|
288 {
|
Chris@16
|
289 std::size_t seed = 0;
|
Chris@16
|
290
|
Chris@16
|
291 for(; first != last; ++first)
|
Chris@16
|
292 {
|
Chris@16
|
293 boost::hash<T> hasher;
|
Chris@16
|
294 seed ^= hasher(*first) + 0x9e3779b9 + (seed<<6) + (seed>>2);
|
Chris@16
|
295 }
|
Chris@16
|
296
|
Chris@16
|
297 return seed;
|
Chris@16
|
298 }
|
Chris@16
|
299
|
Chris@16
|
300 template <class T>
|
Chris@16
|
301 inline void hash_range(std::size_t& seed, T* first, T* last)
|
Chris@16
|
302 {
|
Chris@16
|
303 for(; first != last; ++first)
|
Chris@16
|
304 {
|
Chris@16
|
305 boost::hash<T> hasher;
|
Chris@16
|
306 seed ^= hasher(*first) + 0x9e3779b9 + (seed<<6) + (seed>>2);
|
Chris@16
|
307 }
|
Chris@16
|
308 }
|
Chris@16
|
309 #endif
|
Chris@16
|
310
|
Chris@16
|
311 #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
Chris@16
|
312 template< class T, unsigned N >
|
Chris@16
|
313 inline std::size_t hash_value(const T (&x)[N])
|
Chris@16
|
314 {
|
Chris@16
|
315 return hash_range(x, x + N);
|
Chris@16
|
316 }
|
Chris@16
|
317
|
Chris@16
|
318 template< class T, unsigned N >
|
Chris@16
|
319 inline std::size_t hash_value(T (&x)[N])
|
Chris@16
|
320 {
|
Chris@16
|
321 return hash_range(x, x + N);
|
Chris@16
|
322 }
|
Chris@16
|
323 #endif
|
Chris@16
|
324
|
Chris@16
|
325 template <class Ch, class A>
|
Chris@16
|
326 inline std::size_t hash_value(
|
Chris@16
|
327 std::basic_string<Ch, std::BOOST_HASH_CHAR_TRAITS<Ch>, A> const& v)
|
Chris@16
|
328 {
|
Chris@16
|
329 return hash_range(v.begin(), v.end());
|
Chris@16
|
330 }
|
Chris@16
|
331
|
Chris@16
|
332 template <typename T>
|
Chris@16
|
333 typename boost::hash_detail::float_numbers<T>::type hash_value(T v)
|
Chris@16
|
334 {
|
Chris@16
|
335 return boost::hash_detail::float_hash_value(v);
|
Chris@16
|
336 }
|
Chris@16
|
337
|
Chris@16
|
338 #if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX)
|
Chris@16
|
339 inline std::size_t hash_value(std::type_index v)
|
Chris@16
|
340 {
|
Chris@16
|
341 return v.hash_code();
|
Chris@16
|
342 }
|
Chris@16
|
343 #endif
|
Chris@16
|
344
|
Chris@16
|
345 //
|
Chris@16
|
346 // boost::hash
|
Chris@16
|
347 //
|
Chris@16
|
348
|
Chris@16
|
349 // Define the specializations required by the standard. The general purpose
|
Chris@16
|
350 // boost::hash is defined later in extensions.hpp if
|
Chris@16
|
351 // BOOST_HASH_NO_EXTENSIONS is not defined.
|
Chris@16
|
352
|
Chris@16
|
353 // BOOST_HASH_SPECIALIZE - define a specialization for a type which is
|
Chris@16
|
354 // passed by copy.
|
Chris@16
|
355 //
|
Chris@16
|
356 // BOOST_HASH_SPECIALIZE_REF - define a specialization for a type which is
|
Chris@16
|
357 // passed by copy.
|
Chris@16
|
358 //
|
Chris@16
|
359 // These are undefined later.
|
Chris@16
|
360
|
Chris@16
|
361 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
Chris@16
|
362 #define BOOST_HASH_SPECIALIZE(type) \
|
Chris@16
|
363 template <> struct hash<type> \
|
Chris@16
|
364 : public std::unary_function<type, std::size_t> \
|
Chris@16
|
365 { \
|
Chris@16
|
366 std::size_t operator()(type v) const \
|
Chris@16
|
367 { \
|
Chris@16
|
368 return boost::hash_value(v); \
|
Chris@16
|
369 } \
|
Chris@16
|
370 };
|
Chris@16
|
371
|
Chris@16
|
372 #define BOOST_HASH_SPECIALIZE_REF(type) \
|
Chris@16
|
373 template <> struct hash<type> \
|
Chris@16
|
374 : public std::unary_function<type, std::size_t> \
|
Chris@16
|
375 { \
|
Chris@16
|
376 std::size_t operator()(type const& v) const \
|
Chris@16
|
377 { \
|
Chris@16
|
378 return boost::hash_value(v); \
|
Chris@16
|
379 } \
|
Chris@16
|
380 };
|
Chris@16
|
381 #else
|
Chris@16
|
382 #define BOOST_HASH_SPECIALIZE(type) \
|
Chris@16
|
383 template <> struct hash<type> \
|
Chris@16
|
384 : public std::unary_function<type, std::size_t> \
|
Chris@16
|
385 { \
|
Chris@16
|
386 std::size_t operator()(type v) const \
|
Chris@16
|
387 { \
|
Chris@16
|
388 return boost::hash_value(v); \
|
Chris@16
|
389 } \
|
Chris@16
|
390 }; \
|
Chris@16
|
391 \
|
Chris@16
|
392 template <> struct hash<const type> \
|
Chris@16
|
393 : public std::unary_function<const type, std::size_t> \
|
Chris@16
|
394 { \
|
Chris@16
|
395 std::size_t operator()(const type v) const \
|
Chris@16
|
396 { \
|
Chris@16
|
397 return boost::hash_value(v); \
|
Chris@16
|
398 } \
|
Chris@16
|
399 };
|
Chris@16
|
400
|
Chris@16
|
401 #define BOOST_HASH_SPECIALIZE_REF(type) \
|
Chris@16
|
402 template <> struct hash<type> \
|
Chris@16
|
403 : public std::unary_function<type, std::size_t> \
|
Chris@16
|
404 { \
|
Chris@16
|
405 std::size_t operator()(type const& v) const \
|
Chris@16
|
406 { \
|
Chris@16
|
407 return boost::hash_value(v); \
|
Chris@16
|
408 } \
|
Chris@16
|
409 }; \
|
Chris@16
|
410 \
|
Chris@16
|
411 template <> struct hash<const type> \
|
Chris@16
|
412 : public std::unary_function<const type, std::size_t> \
|
Chris@16
|
413 { \
|
Chris@16
|
414 std::size_t operator()(type const& v) const \
|
Chris@16
|
415 { \
|
Chris@16
|
416 return boost::hash_value(v); \
|
Chris@16
|
417 } \
|
Chris@16
|
418 };
|
Chris@16
|
419 #endif
|
Chris@16
|
420
|
Chris@16
|
421 BOOST_HASH_SPECIALIZE(bool)
|
Chris@16
|
422 BOOST_HASH_SPECIALIZE(char)
|
Chris@16
|
423 BOOST_HASH_SPECIALIZE(signed char)
|
Chris@16
|
424 BOOST_HASH_SPECIALIZE(unsigned char)
|
Chris@16
|
425 #if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
Chris@16
|
426 BOOST_HASH_SPECIALIZE(wchar_t)
|
Chris@16
|
427 #endif
|
Chris@16
|
428 BOOST_HASH_SPECIALIZE(short)
|
Chris@16
|
429 BOOST_HASH_SPECIALIZE(unsigned short)
|
Chris@16
|
430 BOOST_HASH_SPECIALIZE(int)
|
Chris@16
|
431 BOOST_HASH_SPECIALIZE(unsigned int)
|
Chris@16
|
432 BOOST_HASH_SPECIALIZE(long)
|
Chris@16
|
433 BOOST_HASH_SPECIALIZE(unsigned long)
|
Chris@16
|
434
|
Chris@16
|
435 BOOST_HASH_SPECIALIZE(float)
|
Chris@16
|
436 BOOST_HASH_SPECIALIZE(double)
|
Chris@16
|
437 BOOST_HASH_SPECIALIZE(long double)
|
Chris@16
|
438
|
Chris@16
|
439 BOOST_HASH_SPECIALIZE_REF(std::string)
|
Chris@16
|
440 #if !defined(BOOST_NO_STD_WSTRING)
|
Chris@16
|
441 BOOST_HASH_SPECIALIZE_REF(std::wstring)
|
Chris@16
|
442 #endif
|
Chris@16
|
443
|
Chris@16
|
444 #if !defined(BOOST_NO_LONG_LONG)
|
Chris@16
|
445 BOOST_HASH_SPECIALIZE(boost::long_long_type)
|
Chris@16
|
446 BOOST_HASH_SPECIALIZE(boost::ulong_long_type)
|
Chris@16
|
447 #endif
|
Chris@16
|
448
|
Chris@16
|
449 #if defined(BOOST_HAS_INT128)
|
Chris@16
|
450 BOOST_HASH_SPECIALIZE(boost::int128_type)
|
Chris@16
|
451 BOOST_HASH_SPECIALIZE(boost::uint128_type)
|
Chris@16
|
452 #endif
|
Chris@16
|
453
|
Chris@16
|
454 #if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX)
|
Chris@16
|
455 BOOST_HASH_SPECIALIZE(std::type_index)
|
Chris@16
|
456 #endif
|
Chris@16
|
457
|
Chris@16
|
458 #undef BOOST_HASH_SPECIALIZE
|
Chris@16
|
459 #undef BOOST_HASH_SPECIALIZE_REF
|
Chris@16
|
460
|
Chris@16
|
461 // Specializing boost::hash for pointers.
|
Chris@16
|
462
|
Chris@16
|
463 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
Chris@16
|
464
|
Chris@16
|
465 template <class T>
|
Chris@16
|
466 struct hash<T*>
|
Chris@16
|
467 : public std::unary_function<T*, std::size_t>
|
Chris@16
|
468 {
|
Chris@16
|
469 std::size_t operator()(T* v) const
|
Chris@16
|
470 {
|
Chris@16
|
471 #if !BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)
|
Chris@16
|
472 return boost::hash_value(v);
|
Chris@16
|
473 #else
|
Chris@16
|
474 std::size_t x = static_cast<std::size_t>(
|
Chris@16
|
475 reinterpret_cast<std::ptrdiff_t>(v));
|
Chris@16
|
476
|
Chris@16
|
477 return x + (x >> 3);
|
Chris@16
|
478 #endif
|
Chris@16
|
479 }
|
Chris@16
|
480 };
|
Chris@16
|
481
|
Chris@16
|
482 #else
|
Chris@16
|
483
|
Chris@16
|
484 // For compilers without partial specialization, we define a
|
Chris@16
|
485 // boost::hash for all remaining types. But hash_impl is only defined
|
Chris@16
|
486 // for pointers in 'extensions.hpp' - so when BOOST_HASH_NO_EXTENSIONS
|
Chris@16
|
487 // is defined there will still be a compile error for types not supported
|
Chris@16
|
488 // in the standard.
|
Chris@16
|
489
|
Chris@16
|
490 namespace hash_detail
|
Chris@16
|
491 {
|
Chris@16
|
492 template <bool IsPointer>
|
Chris@16
|
493 struct hash_impl;
|
Chris@16
|
494
|
Chris@16
|
495 template <>
|
Chris@16
|
496 struct hash_impl<true>
|
Chris@16
|
497 {
|
Chris@16
|
498 template <class T>
|
Chris@16
|
499 struct inner
|
Chris@16
|
500 : public std::unary_function<T, std::size_t>
|
Chris@16
|
501 {
|
Chris@16
|
502 std::size_t operator()(T val) const
|
Chris@16
|
503 {
|
Chris@16
|
504 #if !BOOST_WORKAROUND(__SUNPRO_CC, <= 590)
|
Chris@16
|
505 return boost::hash_value(val);
|
Chris@16
|
506 #else
|
Chris@16
|
507 std::size_t x = static_cast<std::size_t>(
|
Chris@16
|
508 reinterpret_cast<std::ptrdiff_t>(val));
|
Chris@16
|
509
|
Chris@16
|
510 return x + (x >> 3);
|
Chris@16
|
511 #endif
|
Chris@16
|
512 }
|
Chris@16
|
513 };
|
Chris@16
|
514 };
|
Chris@16
|
515 }
|
Chris@16
|
516
|
Chris@16
|
517 template <class T> struct hash
|
Chris@16
|
518 : public boost::hash_detail::hash_impl<boost::is_pointer<T>::value>
|
Chris@16
|
519 ::BOOST_NESTED_TEMPLATE inner<T>
|
Chris@16
|
520 {
|
Chris@16
|
521 };
|
Chris@16
|
522
|
Chris@16
|
523 #endif
|
Chris@16
|
524 }
|
Chris@16
|
525
|
Chris@16
|
526 #undef BOOST_HASH_CHAR_TRAITS
|
Chris@16
|
527
|
Chris@16
|
528 #if defined(BOOST_MSVC)
|
Chris@16
|
529 #pragma warning(pop)
|
Chris@16
|
530 #endif
|
Chris@16
|
531
|
Chris@16
|
532 #endif // BOOST_FUNCTIONAL_HASH_HASH_HPP
|
Chris@16
|
533
|
Chris@16
|
534 // Include this outside of the include guards in case the file is included
|
Chris@16
|
535 // twice - once with BOOST_HASH_NO_EXTENSIONS defined, and then with it
|
Chris@16
|
536 // undefined.
|
Chris@16
|
537
|
Chris@16
|
538 #if !defined(BOOST_HASH_NO_EXTENSIONS) \
|
Chris@16
|
539 && !defined(BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP)
|
Chris@16
|
540 #include <boost/functional/hash/extensions.hpp>
|
Chris@16
|
541 #endif
|