]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/container_hash/hash.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / container_hash / hash.hpp
1
2 // Copyright 2005-2014 Daniel James.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 // Based on Peter Dimov's proposal
7 // http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf
8 // issue 6.18.
9 //
10 // This also contains public domain code from MurmurHash. From the
11 // MurmurHash header:
12
13 // MurmurHash3 was written by Austin Appleby, and is placed in the public
14 // domain. The author hereby disclaims copyright to this source code.
15
16 #if !defined(BOOST_FUNCTIONAL_HASH_HASH_HPP)
17 #define BOOST_FUNCTIONAL_HASH_HASH_HPP
18
19 #include <boost/container_hash/hash_fwd.hpp>
20 #include <functional>
21 #include <iterator>
22 #include <boost/container_hash/detail/hash_float.hpp>
23 #include <string>
24 #include <boost/limits.hpp>
25 #include <boost/type_traits/is_enum.hpp>
26 #include <boost/type_traits/is_integral.hpp>
27 #include <boost/core/enable_if.hpp>
28 #include <boost/cstdint.hpp>
29 #include <climits>
30
31 #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
32 #include <boost/type_traits/is_pointer.hpp>
33 #endif
34
35 #if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX)
36 #include <typeindex>
37 #endif
38
39 #if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR)
40 #include <system_error>
41 #endif
42
43 #if defined(BOOST_MSVC)
44 #pragma warning(push)
45
46 #if BOOST_MSVC >= 1400
47 #pragma warning(disable:6295) // Ill-defined for-loop : 'unsigned int' values
48 // are always of range '0' to '4294967295'.
49 // Loop executes infinitely.
50 #endif
51
52 #endif
53
54 #if BOOST_WORKAROUND(__GNUC__, < 3) \
55 && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
56 #define BOOST_HASH_CHAR_TRAITS string_char_traits
57 #else
58 #define BOOST_HASH_CHAR_TRAITS char_traits
59 #endif
60
61 #if defined(_MSC_VER)
62 # define BOOST_FUNCTIONAL_HASH_ROTL32(x, r) _rotl(x,r)
63 #else
64 # define BOOST_FUNCTIONAL_HASH_ROTL32(x, r) (x << r) | (x >> (32 - r))
65 #endif
66
67 // Detect whether standard library has C++17 headers
68
69 #if !defined(BOOST_HASH_CXX17)
70 # if defined(BOOST_MSVC)
71 # if defined(_HAS_CXX17) && _HAS_CXX17
72 # define BOOST_HASH_CXX17 1
73 # endif
74 # elif defined(__cplusplus) && __cplusplus >= 201703
75 # define BOOST_HASH_CXX17 1
76 # endif
77 #endif
78
79 #if !defined(BOOST_HASH_CXX17)
80 # define BOOST_HASH_CXX17 0
81 #endif
82
83 #if BOOST_HASH_CXX17 && defined(__has_include)
84 # if !defined(BOOST_HASH_HAS_STRING_VIEW) && __has_include(<string_view>)
85 # define BOOST_HASH_HAS_STRING_VIEW 1
86 # endif
87 # if !defined(BOOST_HASH_HAS_OPTIONAL) && __has_include(<optional>)
88 # define BOOST_HASH_HAS_OPTIONAL 1
89 # endif
90 # if !defined(BOOST_HASH_HAS_VARIANT) && __has_include(<variant>)
91 # define BOOST_HASH_HAS_VARIANT 1
92 # endif
93 #endif
94
95 #if !defined(BOOST_HASH_HAS_STRING_VIEW)
96 # define BOOST_HASH_HAS_STRING_VIEW 0
97 #endif
98
99 #if !defined(BOOST_HASH_HAS_OPTIONAL)
100 # define BOOST_HASH_HAS_OPTIONAL 0
101 #endif
102
103 #if !defined(BOOST_HASH_HAS_VARIANT)
104 # define BOOST_HASH_HAS_VARIANT 0
105 #endif
106
107 #if BOOST_HASH_HAS_STRING_VIEW
108 # include <string_view>
109 #endif
110
111 #if BOOST_HASH_HAS_OPTIONAL
112 # include <optional>
113 #endif
114
115 #if BOOST_HASH_HAS_VARIANT
116 # include <variant>
117 #endif
118
119 namespace boost
120 {
121 namespace hash_detail
122 {
123 #if defined(BOOST_NO_CXX98_FUNCTION_BASE)
124 template <typename T>
125 struct hash_base
126 {
127 typedef T argument_type;
128 typedef std::size_t result_type;
129 };
130 #else
131 template <typename T>
132 struct hash_base : std::unary_function<T, std::size_t> {};
133 #endif
134
135 struct enable_hash_value { typedef std::size_t type; };
136
137 template <typename T> struct basic_numbers {};
138 template <typename T> struct long_numbers;
139 template <typename T> struct ulong_numbers;
140 template <typename T> struct float_numbers {};
141
142 template <> struct basic_numbers<bool> :
143 boost::hash_detail::enable_hash_value {};
144 template <> struct basic_numbers<char> :
145 boost::hash_detail::enable_hash_value {};
146 template <> struct basic_numbers<unsigned char> :
147 boost::hash_detail::enable_hash_value {};
148 template <> struct basic_numbers<signed char> :
149 boost::hash_detail::enable_hash_value {};
150 template <> struct basic_numbers<short> :
151 boost::hash_detail::enable_hash_value {};
152 template <> struct basic_numbers<unsigned short> :
153 boost::hash_detail::enable_hash_value {};
154 template <> struct basic_numbers<int> :
155 boost::hash_detail::enable_hash_value {};
156 template <> struct basic_numbers<unsigned int> :
157 boost::hash_detail::enable_hash_value {};
158 template <> struct basic_numbers<long> :
159 boost::hash_detail::enable_hash_value {};
160 template <> struct basic_numbers<unsigned long> :
161 boost::hash_detail::enable_hash_value {};
162
163 #if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
164 template <> struct basic_numbers<wchar_t> :
165 boost::hash_detail::enable_hash_value {};
166 #endif
167
168 #if !defined(BOOST_NO_CXX11_CHAR16_T)
169 template <> struct basic_numbers<char16_t> :
170 boost::hash_detail::enable_hash_value {};
171 #endif
172
173 #if !defined(BOOST_NO_CXX11_CHAR32_T)
174 template <> struct basic_numbers<char32_t> :
175 boost::hash_detail::enable_hash_value {};
176 #endif
177
178 // long_numbers is defined like this to allow for separate
179 // specialization for long_long and int128_type, in case
180 // they conflict.
181 template <typename T> struct long_numbers2 {};
182 template <typename T> struct ulong_numbers2 {};
183 template <typename T> struct long_numbers : long_numbers2<T> {};
184 template <typename T> struct ulong_numbers : ulong_numbers2<T> {};
185
186 #if !defined(BOOST_NO_LONG_LONG)
187 template <> struct long_numbers<boost::long_long_type> :
188 boost::hash_detail::enable_hash_value {};
189 template <> struct ulong_numbers<boost::ulong_long_type> :
190 boost::hash_detail::enable_hash_value {};
191 #endif
192
193 #if defined(BOOST_HAS_INT128)
194 template <> struct long_numbers2<boost::int128_type> :
195 boost::hash_detail::enable_hash_value {};
196 template <> struct ulong_numbers2<boost::uint128_type> :
197 boost::hash_detail::enable_hash_value {};
198 #endif
199
200 template <> struct float_numbers<float> :
201 boost::hash_detail::enable_hash_value {};
202 template <> struct float_numbers<double> :
203 boost::hash_detail::enable_hash_value {};
204 template <> struct float_numbers<long double> :
205 boost::hash_detail::enable_hash_value {};
206 }
207
208 template <typename T>
209 typename boost::hash_detail::basic_numbers<T>::type hash_value(T);
210 template <typename T>
211 typename boost::hash_detail::long_numbers<T>::type hash_value(T);
212 template <typename T>
213 typename boost::hash_detail::ulong_numbers<T>::type hash_value(T);
214
215 template <typename T>
216 typename boost::enable_if<boost::is_enum<T>, std::size_t>::type
217 hash_value(T);
218
219 #if !BOOST_WORKAROUND(__DMC__, <= 0x848)
220 template <class T> std::size_t hash_value(T* const&);
221 #else
222 template <class T> std::size_t hash_value(T*);
223 #endif
224
225 #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
226 template< class T, unsigned N >
227 std::size_t hash_value(const T (&x)[N]);
228
229 template< class T, unsigned N >
230 std::size_t hash_value(T (&x)[N]);
231 #endif
232
233 template <class Ch, class A>
234 std::size_t hash_value(
235 std::basic_string<Ch, std::BOOST_HASH_CHAR_TRAITS<Ch>, A> const&);
236
237 #if BOOST_HASH_HAS_STRING_VIEW
238 template <class Ch>
239 std::size_t hash_value(
240 std::basic_string_view<Ch, std::BOOST_HASH_CHAR_TRAITS<Ch> > const&);
241 #endif
242
243 template <typename T>
244 typename boost::hash_detail::float_numbers<T>::type hash_value(T);
245
246 #if BOOST_HASH_HAS_OPTIONAL
247 template <typename T>
248 std::size_t hash_value(std::optional<T> const&);
249 #endif
250
251 #if BOOST_HASH_HAS_VARIANT
252 std::size_t hash_value(std::monostate);
253 template <typename... Types>
254 std::size_t hash_value(std::variant<Types...> const&);
255 #endif
256
257 #if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX)
258 std::size_t hash_value(std::type_index);
259 #endif
260
261 #if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR)
262 std::size_t hash_value(std::error_code const&);
263 std::size_t hash_value(std::error_condition const&);
264 #endif
265
266 // Implementation
267
268 namespace hash_detail
269 {
270 template <class T>
271 inline std::size_t hash_value_signed(T val)
272 {
273 const unsigned int size_t_bits = std::numeric_limits<std::size_t>::digits;
274 // ceiling(std::numeric_limits<T>::digits / size_t_bits) - 1
275 const int length = (std::numeric_limits<T>::digits - 1)
276 / static_cast<int>(size_t_bits);
277
278 std::size_t seed = 0;
279 T positive = val < 0 ? -1 - val : val;
280
281 // Hopefully, this loop can be unrolled.
282 for(unsigned int i = length * size_t_bits; i > 0; i -= size_t_bits)
283 {
284 seed ^= (std::size_t) (positive >> i) + (seed<<6) + (seed>>2);
285 }
286 seed ^= (std::size_t) val + (seed<<6) + (seed>>2);
287
288 return seed;
289 }
290
291 template <class T>
292 inline std::size_t hash_value_unsigned(T val)
293 {
294 const unsigned int size_t_bits = std::numeric_limits<std::size_t>::digits;
295 // ceiling(std::numeric_limits<T>::digits / size_t_bits) - 1
296 const int length = (std::numeric_limits<T>::digits - 1)
297 / static_cast<int>(size_t_bits);
298
299 std::size_t seed = 0;
300
301 // Hopefully, this loop can be unrolled.
302 for(unsigned int i = length * size_t_bits; i > 0; i -= size_t_bits)
303 {
304 seed ^= (std::size_t) (val >> i) + (seed<<6) + (seed>>2);
305 }
306 seed ^= (std::size_t) val + (seed<<6) + (seed>>2);
307
308 return seed;
309 }
310
311 template<std::size_t Bits> struct hash_combine_impl
312 {
313 template <typename SizeT>
314 inline static SizeT fn(SizeT seed, SizeT value)
315 {
316 seed ^= value + 0x9e3779b9 + (seed<<6) + (seed>>2);
317 return seed;
318 }
319 };
320
321 template<> struct hash_combine_impl<32>
322 {
323 inline static boost::uint32_t fn(boost::uint32_t h1, boost::uint32_t k1)
324 {
325 const boost::uint32_t c1 = 0xcc9e2d51;
326 const boost::uint32_t c2 = 0x1b873593;
327
328 k1 *= c1;
329 k1 = BOOST_FUNCTIONAL_HASH_ROTL32(k1,15);
330 k1 *= c2;
331
332 h1 ^= k1;
333 h1 = BOOST_FUNCTIONAL_HASH_ROTL32(h1,13);
334 h1 = h1*5+0xe6546b64;
335
336 return h1;
337 }
338 };
339
340 template<> struct hash_combine_impl<64>
341 {
342 inline static boost::uint64_t fn(boost::uint64_t h, boost::uint64_t k)
343 {
344 const boost::uint64_t m = (boost::uint64_t(0xc6a4a793) << 32) + 0x5bd1e995;
345 const int r = 47;
346
347 k *= m;
348 k ^= k >> r;
349 k *= m;
350
351 h ^= k;
352 h *= m;
353
354 // Completely arbitrary number, to prevent 0's
355 // from hashing to 0.
356 h += 0xe6546b64;
357
358 return h;
359 }
360 };
361 }
362
363 template <typename T>
364 typename boost::hash_detail::basic_numbers<T>::type hash_value(T v)
365 {
366 return static_cast<std::size_t>(v);
367 }
368
369 template <typename T>
370 typename boost::hash_detail::long_numbers<T>::type hash_value(T v)
371 {
372 return hash_detail::hash_value_signed(v);
373 }
374
375 template <typename T>
376 typename boost::hash_detail::ulong_numbers<T>::type hash_value(T v)
377 {
378 return hash_detail::hash_value_unsigned(v);
379 }
380
381 template <typename T>
382 typename boost::enable_if<boost::is_enum<T>, std::size_t>::type
383 hash_value(T v)
384 {
385 return static_cast<std::size_t>(v);
386 }
387
388 // Implementation by Alberto Barbati and Dave Harris.
389 #if !BOOST_WORKAROUND(__DMC__, <= 0x848)
390 template <class T> std::size_t hash_value(T* const& v)
391 #else
392 template <class T> std::size_t hash_value(T* v)
393 #endif
394 {
395 #if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
396 // for some reason ptrdiff_t on OpenVMS compiler with
397 // 64 bit is not 64 bit !!!
398 std::size_t x = static_cast<std::size_t>(
399 reinterpret_cast<long long int>(v));
400 #else
401 std::size_t x = static_cast<std::size_t>(
402 reinterpret_cast<std::ptrdiff_t>(v));
403 #endif
404 return x + (x >> 3);
405 }
406
407 #if defined(BOOST_MSVC)
408 #pragma warning(push)
409 #if BOOST_MSVC <= 1400
410 #pragma warning(disable:4267) // 'argument' : conversion from 'size_t' to
411 // 'unsigned int', possible loss of data
412 // A misguided attempt to detect 64-bit
413 // incompatability.
414 #endif
415 #endif
416
417 template <class T>
418 inline void hash_combine(std::size_t& seed, T const& v)
419 {
420 boost::hash<T> hasher;
421 seed = boost::hash_detail::hash_combine_impl<sizeof(std::size_t) * CHAR_BIT>::fn(seed, hasher(v));
422 }
423
424 #if defined(BOOST_MSVC)
425 #pragma warning(pop)
426 #endif
427
428 template <class It>
429 inline std::size_t hash_range(It first, It last)
430 {
431 std::size_t seed = 0;
432
433 for(; first != last; ++first)
434 {
435 hash_combine<typename std::iterator_traits<It>::value_type>(seed, *first);
436 }
437
438 return seed;
439 }
440
441 template <class It>
442 inline void hash_range(std::size_t& seed, It first, It last)
443 {
444 for(; first != last; ++first)
445 {
446 hash_combine<typename std::iterator_traits<It>::value_type>(seed, *first);
447 }
448 }
449
450 #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x551))
451 template <class T>
452 inline std::size_t hash_range(T* first, T* last)
453 {
454 std::size_t seed = 0;
455
456 for(; first != last; ++first)
457 {
458 boost::hash<T> hasher;
459 seed ^= hasher(*first) + 0x9e3779b9 + (seed<<6) + (seed>>2);
460 }
461
462 return seed;
463 }
464
465 template <class T>
466 inline void hash_range(std::size_t& seed, T* first, T* last)
467 {
468 for(; first != last; ++first)
469 {
470 boost::hash<T> hasher;
471 seed ^= hasher(*first) + 0x9e3779b9 + (seed<<6) + (seed>>2);
472 }
473 }
474 #endif
475
476 #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
477 template< class T, unsigned N >
478 inline std::size_t hash_value(const T (&x)[N])
479 {
480 return hash_range(x, x + N);
481 }
482
483 template< class T, unsigned N >
484 inline std::size_t hash_value(T (&x)[N])
485 {
486 return hash_range(x, x + N);
487 }
488 #endif
489
490 template <class Ch, class A>
491 inline std::size_t hash_value(
492 std::basic_string<Ch, std::BOOST_HASH_CHAR_TRAITS<Ch>, A> const& v)
493 {
494 return hash_range(v.begin(), v.end());
495 }
496
497 #if BOOST_HASH_HAS_STRING_VIEW
498 template <class Ch>
499 inline std::size_t hash_value(
500 std::basic_string_view<Ch, std::BOOST_HASH_CHAR_TRAITS<Ch> > const& v)
501 {
502 return hash_range(v.begin(), v.end());
503 }
504 #endif
505
506 template <typename T>
507 typename boost::hash_detail::float_numbers<T>::type hash_value(T v)
508 {
509 return boost::hash_detail::float_hash_value(v);
510 }
511
512 #if BOOST_HASH_HAS_OPTIONAL
513 template <typename T>
514 inline std::size_t hash_value(std::optional<T> const& v) {
515 if (!v) {
516 // Arbitray value for empty optional.
517 return 0x12345678;
518 } else {
519 boost::hash<T> hf;
520 return hf(*v);
521 }
522 }
523 #endif
524
525 #if BOOST_HASH_HAS_VARIANT
526 inline std::size_t hash_value(std::monostate) {
527 return 0x87654321;
528 }
529
530 template <typename... Types>
531 inline std::size_t hash_value(std::variant<Types...> const& v) {
532 std::size_t seed = 0;
533 hash_combine(seed, v.index());
534 std::visit([&seed](auto&& x) { hash_combine(seed, x); }, v);
535 return seed;
536 }
537 #endif
538
539
540 #if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX)
541 inline std::size_t hash_value(std::type_index v)
542 {
543 return v.hash_code();
544 }
545 #endif
546
547 #if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR)
548 inline std::size_t hash_value(std::error_code const& v) {
549 std::size_t seed = 0;
550 hash_combine(seed, v.value());
551 hash_combine(seed, &v.category());
552 return seed;
553 }
554
555 inline std::size_t hash_value(std::error_condition const& v) {
556 std::size_t seed = 0;
557 hash_combine(seed, v.value());
558 hash_combine(seed, &v.category());
559 return seed;
560 }
561 #endif
562
563 //
564 // boost::hash
565 //
566
567 // Define the specializations required by the standard. The general purpose
568 // boost::hash is defined later in extensions.hpp if
569 // BOOST_HASH_NO_EXTENSIONS is not defined.
570
571 // BOOST_HASH_SPECIALIZE - define a specialization for a type which is
572 // passed by copy.
573 //
574 // BOOST_HASH_SPECIALIZE_REF - define a specialization for a type which is
575 // passed by const reference.
576 //
577 // These are undefined later.
578
579 #define BOOST_HASH_SPECIALIZE(type) \
580 template <> struct hash<type> \
581 : public boost::hash_detail::hash_base<type> \
582 { \
583 std::size_t operator()(type v) const \
584 { \
585 return boost::hash_value(v); \
586 } \
587 };
588
589 #define BOOST_HASH_SPECIALIZE_REF(type) \
590 template <> struct hash<type> \
591 : public boost::hash_detail::hash_base<type> \
592 { \
593 std::size_t operator()(type const& v) const \
594 { \
595 return boost::hash_value(v); \
596 } \
597 };
598
599 #define BOOST_HASH_SPECIALIZE_TEMPLATE_REF(type) \
600 struct hash<type> \
601 : public boost::hash_detail::hash_base<type> \
602 { \
603 std::size_t operator()(type const& v) const \
604 { \
605 return boost::hash_value(v); \
606 } \
607 };
608
609 BOOST_HASH_SPECIALIZE(bool)
610 BOOST_HASH_SPECIALIZE(char)
611 BOOST_HASH_SPECIALIZE(signed char)
612 BOOST_HASH_SPECIALIZE(unsigned char)
613 #if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
614 BOOST_HASH_SPECIALIZE(wchar_t)
615 #endif
616 #if !defined(BOOST_NO_CXX11_CHAR16_T)
617 BOOST_HASH_SPECIALIZE(char16_t)
618 #endif
619 #if !defined(BOOST_NO_CXX11_CHAR32_T)
620 BOOST_HASH_SPECIALIZE(char32_t)
621 #endif
622 BOOST_HASH_SPECIALIZE(short)
623 BOOST_HASH_SPECIALIZE(unsigned short)
624 BOOST_HASH_SPECIALIZE(int)
625 BOOST_HASH_SPECIALIZE(unsigned int)
626 BOOST_HASH_SPECIALIZE(long)
627 BOOST_HASH_SPECIALIZE(unsigned long)
628
629 BOOST_HASH_SPECIALIZE(float)
630 BOOST_HASH_SPECIALIZE(double)
631 BOOST_HASH_SPECIALIZE(long double)
632
633 BOOST_HASH_SPECIALIZE_REF(std::string)
634 #if !defined(BOOST_NO_STD_WSTRING) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
635 BOOST_HASH_SPECIALIZE_REF(std::wstring)
636 #endif
637 #if !defined(BOOST_NO_CXX11_CHAR16_T)
638 BOOST_HASH_SPECIALIZE_REF(std::basic_string<char16_t>)
639 #endif
640 #if !defined(BOOST_NO_CXX11_CHAR32_T)
641 BOOST_HASH_SPECIALIZE_REF(std::basic_string<char32_t>)
642 #endif
643
644 #if BOOST_HASH_HAS_STRING_VIEW
645 BOOST_HASH_SPECIALIZE_REF(std::string_view)
646 # if !defined(BOOST_NO_STD_WSTRING) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
647 BOOST_HASH_SPECIALIZE_REF(std::wstring_view)
648 # endif
649 # if !defined(BOOST_NO_CXX11_CHAR16_T)
650 BOOST_HASH_SPECIALIZE_REF(std::basic_string_view<char16_t>)
651 # endif
652 # if !defined(BOOST_NO_CXX11_CHAR32_T)
653 BOOST_HASH_SPECIALIZE_REF(std::basic_string_view<char32_t>)
654 # endif
655 #endif
656
657 #if !defined(BOOST_NO_LONG_LONG)
658 BOOST_HASH_SPECIALIZE(boost::long_long_type)
659 BOOST_HASH_SPECIALIZE(boost::ulong_long_type)
660 #endif
661
662 #if defined(BOOST_HAS_INT128)
663 BOOST_HASH_SPECIALIZE(boost::int128_type)
664 BOOST_HASH_SPECIALIZE(boost::uint128_type)
665 #endif
666
667 #if BOOST_HASH_HAS_OPTIONAL
668 template <typename T>
669 BOOST_HASH_SPECIALIZE_TEMPLATE_REF(std::optional<T>)
670 #endif
671
672 #if !defined(BOOST_HASH_HAS_VARIANT)
673 template <typename... T>
674 BOOST_HASH_SPECIALIZE_TEMPLATE_REF(std::variant<T...>)
675 BOOST_HASH_SPECIALIZE(std::monostate)
676 #endif
677
678 #if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX)
679 BOOST_HASH_SPECIALIZE(std::type_index)
680 #endif
681
682 #undef BOOST_HASH_SPECIALIZE
683 #undef BOOST_HASH_SPECIALIZE_REF
684 #undef BOOST_HASH_SPECIALIZE_TEMPLATE_REF
685
686 // Specializing boost::hash for pointers.
687
688 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
689
690 template <class T>
691 struct hash<T*>
692 : public boost::hash_detail::hash_base<T*>
693 {
694 std::size_t operator()(T* v) const
695 {
696 #if !BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)
697 return boost::hash_value(v);
698 #else
699 std::size_t x = static_cast<std::size_t>(
700 reinterpret_cast<std::ptrdiff_t>(v));
701
702 return x + (x >> 3);
703 #endif
704 }
705 };
706
707 #else
708
709 // For compilers without partial specialization, we define a
710 // boost::hash for all remaining types. But hash_impl is only defined
711 // for pointers in 'extensions.hpp' - so when BOOST_HASH_NO_EXTENSIONS
712 // is defined there will still be a compile error for types not supported
713 // in the standard.
714
715 namespace hash_detail
716 {
717 template <bool IsPointer>
718 struct hash_impl;
719
720 template <>
721 struct hash_impl<true>
722 {
723 template <class T>
724 struct inner
725 : public boost::hash_detail::hash_base<T>
726 {
727 std::size_t operator()(T val) const
728 {
729 #if !BOOST_WORKAROUND(__SUNPRO_CC, <= 590)
730 return boost::hash_value(val);
731 #else
732 std::size_t x = static_cast<std::size_t>(
733 reinterpret_cast<std::ptrdiff_t>(val));
734
735 return x + (x >> 3);
736 #endif
737 }
738 };
739 };
740 }
741
742 template <class T> struct hash
743 : public boost::hash_detail::hash_impl<boost::is_pointer<T>::value>
744 ::BOOST_NESTED_TEMPLATE inner<T>
745 {
746 };
747
748 #endif
749 }
750
751 #undef BOOST_HASH_CHAR_TRAITS
752 #undef BOOST_FUNCTIONAL_HASH_ROTL32
753
754 #if defined(BOOST_MSVC)
755 #pragma warning(pop)
756 #endif
757
758 #endif // BOOST_FUNCTIONAL_HASH_HASH_HPP
759
760 // Include this outside of the include guards in case the file is included
761 // twice - once with BOOST_HASH_NO_EXTENSIONS defined, and then with it
762 // undefined.
763
764 #if !defined(BOOST_HASH_NO_EXTENSIONS) \
765 && !defined(BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP)
766 #include <boost/container_hash/extensions.hpp>
767 #endif