summaryrefslogtreecommitdiff
path: root/boost/functional/hash
diff options
context:
space:
mode:
Diffstat (limited to 'boost/functional/hash')
-rw-r--r--boost/functional/hash/detail/container_fwd_0x.hpp29
-rw-r--r--boost/functional/hash/detail/float_functions.hpp94
-rw-r--r--boost/functional/hash/detail/hash_float.hpp192
-rw-r--r--boost/functional/hash/detail/hash_float_generic.hpp91
-rw-r--r--boost/functional/hash/detail/hash_float_x86.hpp56
-rw-r--r--boost/functional/hash/detail/limits.hpp5
-rw-r--r--boost/functional/hash/extensions.hpp83
-rw-r--r--boost/functional/hash/hash.hpp161
-rw-r--r--boost/functional/hash/hash_fwd.hpp10
9 files changed, 401 insertions, 320 deletions
diff --git a/boost/functional/hash/detail/container_fwd_0x.hpp b/boost/functional/hash/detail/container_fwd_0x.hpp
deleted file mode 100644
index bed7730fc0..0000000000
--- a/boost/functional/hash/detail/container_fwd_0x.hpp
+++ /dev/null
@@ -1,29 +0,0 @@
-
-// Copyright 2012 Daniel James.
-// Distributed under the Boost Software License, Version 1.0. (See accompanying
-// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-
-#if !defined(BOOST_DETAIL_CONTAINER_FWD_0X_HPP)
-#define BOOST_DETAIL_CONTAINER_FWD_0X_HPP
-
-#include <boost/detail/container_fwd.hpp>
-
-// std::array
-
-#if !defined(BOOST_NO_CXX11_HDR_ARRAY)
-# include <array>
-#endif
-
-// std::tuple
-
-#if !defined(BOOST_NO_CXX11_HDR_TUPLE)
-# include <tuple>
-#endif
-
-// std::shared_ptr/std::unique_ptr
-
-#if !defined(BOOST_NO_CXX11_HDR_MEMORY)
-# include <memory>
-#endif
-
-#endif
diff --git a/boost/functional/hash/detail/float_functions.hpp b/boost/functional/hash/detail/float_functions.hpp
index ae03ff091e..f3db52f9cc 100644
--- a/boost/functional/hash/detail/float_functions.hpp
+++ b/boost/functional/hash/detail/float_functions.hpp
@@ -7,12 +7,100 @@
#define BOOST_FUNCTIONAL_HASH_DETAIL_FLOAT_FUNCTIONS_HPP
#include <boost/config.hpp>
+#if defined(BOOST_HAS_PRAGMA_ONCE)
+#pragma once
+#endif
+
#include <boost/config/no_tr1/cmath.hpp>
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
+// Set BOOST_HASH_CONFORMANT_FLOATS to 1 for libraries known to have
+// sufficiently good floating point support to not require any
+// workarounds.
+//
+// When set to 0, the library tries to automatically
+// use the best available implementation. This normally works well, but
+// breaks when ambiguities are created by odd namespacing of the functions.
+//
+// Note that if this is set to 0, the library should still take full
+// advantage of the platform's floating point support.
+
+#if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
+# define BOOST_HASH_CONFORMANT_FLOATS 0
+#elif defined(__LIBCOMO__)
+# define BOOST_HASH_CONFORMANT_FLOATS 0
+#elif defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER)
+// Rogue Wave library:
+# define BOOST_HASH_CONFORMANT_FLOATS 0
+#elif defined(_LIBCPP_VERSION)
+// libc++
+# define BOOST_HASH_CONFORMANT_FLOATS 1
+#elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
+// GNU libstdc++ 3
+# if defined(__GNUC__) && __GNUC__ >= 4
+# define BOOST_HASH_CONFORMANT_FLOATS 1
+# else
+# define BOOST_HASH_CONFORMANT_FLOATS 0
+# endif
+#elif defined(__STL_CONFIG_H)
+// generic SGI STL
+# define BOOST_HASH_CONFORMANT_FLOATS 0
+#elif defined(__MSL_CPP__)
+// MSL standard lib:
+# define BOOST_HASH_CONFORMANT_FLOATS 0
+#elif defined(__IBMCPP__)
+// VACPP std lib (probably conformant for much earlier version).
+# if __IBMCPP__ >= 1210
+# define BOOST_HASH_CONFORMANT_FLOATS 1
+# else
+# define BOOST_HASH_CONFORMANT_FLOATS 0
+# endif
+#elif defined(MSIPL_COMPILE_H)
+// Modena C++ standard library
+# define BOOST_HASH_CONFORMANT_FLOATS 0
+#elif (defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER)
+// Dinkumware Library (this has to appear after any possible replacement libraries):
+# if _CPPLIB_VER >= 405
+# define BOOST_HASH_CONFORMANT_FLOATS 1
+# else
+# define BOOST_HASH_CONFORMANT_FLOATS 0
+# endif
+#else
+# define BOOST_HASH_CONFORMANT_FLOATS 0
#endif
+#if BOOST_HASH_CONFORMANT_FLOATS
+
+// The standard library is known to be compliant, so don't use the
+// configuration mechanism.
+
+namespace boost {
+ namespace hash_detail {
+ template <typename Float>
+ struct call_ldexp {
+ typedef Float float_type;
+ inline Float operator()(Float x, int y) const {
+ return std::ldexp(x, y);
+ }
+ };
+
+ template <typename Float>
+ struct call_frexp {
+ typedef Float float_type;
+ inline Float operator()(Float x, int* y) const {
+ return std::frexp(x, y);
+ }
+ };
+
+ template <typename Float>
+ struct select_hash_type
+ {
+ typedef Float type;
+ };
+ }
+}
+
+#else // BOOST_HASH_CONFORMANT_FLOATS == 0
+
// The C++ standard requires that the C float functions are overloarded
// for float, double and long double in the std namespace, but some of the older
// library implementations don't support this. On some that don't, the C99
@@ -243,4 +331,6 @@ namespace boost
}
}
+#endif // BOOST_HASH_CONFORMANT_FLOATS
+
#endif
diff --git a/boost/functional/hash/detail/hash_float.hpp b/boost/functional/hash/detail/hash_float.hpp
index 194be1cae5..ee0ee87745 100644
--- a/boost/functional/hash/detail/hash_float.hpp
+++ b/boost/functional/hash/detail/hash_float.hpp
@@ -1,33 +1,31 @@
-// Copyright 2005-2009 Daniel James.
+// Copyright 2005-2012 Daniel James.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_HEADER)
#define BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_HEADER
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
+#include <boost/config.hpp>
+#if defined(BOOST_HAS_PRAGMA_ONCE)
+#pragma once
#endif
-#include <boost/config.hpp>
#include <boost/functional/hash/detail/float_functions.hpp>
#include <boost/functional/hash/detail/limits.hpp>
+#include <boost/utility/enable_if.hpp>
#include <boost/integer/static_log2.hpp>
#include <boost/cstdint.hpp>
#include <boost/assert.hpp>
+#include <boost/limits.hpp>
+#include <cstring>
-// Include hash implementation for the current platform.
-
-// Cygwn
-#if defined(__CYGWIN__)
-# if defined(__i386__) || defined(_M_IX86)
-# include <boost/functional/hash/detail/hash_float_x86.hpp>
-# else
-# include <boost/functional/hash/detail/hash_float_generic.hpp>
-# endif
-#else
-# include <boost/functional/hash/detail/hash_float_generic.hpp>
+#if defined(BOOST_MSVC)
+#pragma warning(push)
+#if BOOST_MSVC >= 1400
+#pragma warning(disable:6294) // Ill-defined for-loop: initial condition does
+ // not satisfy test. Loop body not executed
+#endif
#endif
// Can we use fpclassify?
@@ -50,6 +48,153 @@
# define BOOST_HASH_USE_FPCLASSIFY 0
#endif
+namespace boost
+{
+ namespace hash_detail
+ {
+ inline void hash_float_combine(std::size_t& seed, std::size_t value)
+ {
+ seed ^= value + (seed<<6) + (seed>>2);
+ }
+
+ ////////////////////////////////////////////////////////////////////////
+ // Binary hash function
+ //
+ // Only used for floats with known iec559 floats, and certain values in
+ // numeric_limits
+
+ inline std::size_t hash_binary(char* ptr, std::size_t length)
+ {
+ std::size_t seed = 0;
+
+ if (length >= sizeof(std::size_t)) {
+ seed = *(std::size_t*) ptr;
+ length -= sizeof(std::size_t);
+ ptr += sizeof(std::size_t);
+
+ while(length >= sizeof(std::size_t)) {
+ std::size_t buffer = 0;
+ std::memcpy(&buffer, ptr, sizeof(std::size_t));
+ hash_float_combine(seed, buffer);
+ length -= sizeof(std::size_t);
+ ptr += sizeof(std::size_t);
+ }
+ }
+
+ if (length > 0) {
+ std::size_t buffer = 0;
+ std::memcpy(&buffer, ptr, length);
+ hash_float_combine(seed, buffer);
+ }
+
+ return seed;
+ }
+
+ template <typename Float, unsigned digits, unsigned max_exponent>
+ struct enable_binary_hash
+ {
+ BOOST_STATIC_CONSTANT(bool, value =
+ std::numeric_limits<Float>::is_iec559 &&
+ std::numeric_limits<Float>::digits == digits &&
+ std::numeric_limits<Float>::radix == 2 &&
+ std::numeric_limits<Float>::max_exponent == max_exponent);
+ };
+
+ template <typename Float>
+ inline std::size_t float_hash_impl(Float v,
+ BOOST_DEDUCED_TYPENAME boost::enable_if_c<
+ enable_binary_hash<Float, 24, 128>::value,
+ std::size_t>::type)
+ {
+ return hash_binary((char*) &v, 4);
+ }
+
+
+ template <typename Float>
+ inline std::size_t float_hash_impl(Float v,
+ BOOST_DEDUCED_TYPENAME boost::enable_if_c<
+ enable_binary_hash<Float, 53, 1024>::value,
+ std::size_t>::type)
+ {
+ return hash_binary((char*) &v, 8);
+ }
+
+ template <typename Float>
+ inline std::size_t float_hash_impl(Float v,
+ BOOST_DEDUCED_TYPENAME boost::enable_if_c<
+ enable_binary_hash<Float, 64, 16384>::value,
+ std::size_t>::type)
+ {
+ return hash_binary((char*) &v, 10);
+ }
+
+ template <typename Float>
+ inline std::size_t float_hash_impl(Float v,
+ BOOST_DEDUCED_TYPENAME boost::enable_if_c<
+ enable_binary_hash<Float, 113, 16384>::value,
+ std::size_t>::type)
+ {
+ return hash_binary((char*) &v, 16);
+ }
+
+ ////////////////////////////////////////////////////////////////////////
+ // Portable hash function
+ //
+ // Used as a fallback when the binary hash function isn't supported.
+
+ template <class T>
+ inline std::size_t float_hash_impl2(T v)
+ {
+ boost::hash_detail::call_frexp<T> frexp;
+ boost::hash_detail::call_ldexp<T> ldexp;
+
+ int exp = 0;
+
+ v = frexp(v, &exp);
+
+ // A postive value is easier to hash, so combine the
+ // sign with the exponent and use the absolute value.
+ if(v < 0) {
+ v = -v;
+ exp += limits<T>::max_exponent -
+ limits<T>::min_exponent;
+ }
+
+ v = ldexp(v, limits<std::size_t>::digits);
+ std::size_t seed = static_cast<std::size_t>(v);
+ v -= static_cast<T>(seed);
+
+ // ceiling(digits(T) * log2(radix(T))/ digits(size_t)) - 1;
+ std::size_t const length
+ = (limits<T>::digits *
+ boost::static_log2<limits<T>::radix>::value
+ + limits<std::size_t>::digits - 1)
+ / limits<std::size_t>::digits;
+
+ for(std::size_t i = 0; i != length; ++i)
+ {
+ v = ldexp(v, limits<std::size_t>::digits);
+ std::size_t part = static_cast<std::size_t>(v);
+ v -= static_cast<T>(part);
+ hash_float_combine(seed, part);
+ }
+
+ hash_float_combine(seed, exp);
+
+ return seed;
+ }
+
+#if !defined(BOOST_HASH_DETAIL_TEST_WITHOUT_GENERIC)
+ template <class T>
+ inline std::size_t float_hash_impl(T v, ...)
+ {
+ typedef BOOST_DEDUCED_TYPENAME select_hash_type<T>::type type;
+ return float_hash_impl2(static_cast<type>(v));
+ }
+#endif
+ }
+}
+
#if BOOST_HASH_USE_FPCLASSIFY
#include <boost/config/no_tr1/cmath.hpp>
@@ -61,8 +206,15 @@ namespace boost
template <class T>
inline std::size_t float_hash_value(T v)
{
+#if defined(fpclassify)
+ switch (fpclassify(v))
+#elif BOOST_HASH_CONFORMANT_FLOATS
+ switch (std::fpclassify(v))
+#else
using namespace std;
- switch (fpclassify(v)) {
+ switch (fpclassify(v))
+#endif
+ {
case FP_ZERO:
return 0;
case FP_INFINITE:
@@ -71,7 +223,7 @@ namespace boost
return (std::size_t)(-3);
case FP_NORMAL:
case FP_SUBNORMAL:
- return float_hash_impl(v);
+ return float_hash_impl(v, 0);
default:
BOOST_ASSERT(0);
return 0;
@@ -103,7 +255,7 @@ namespace boost
template <class T>
inline std::size_t float_hash_value(T v)
{
- return boost::hash_detail::is_zero(v) ? 0 : float_hash_impl(v);
+ return boost::hash_detail::is_zero(v) ? 0 : float_hash_impl(v, 0);
}
}
}
@@ -112,4 +264,8 @@ namespace boost
#undef BOOST_HASH_USE_FPCLASSIFY
+#if defined(BOOST_MSVC)
+#pragma warning(pop)
+#endif
+
#endif
diff --git a/boost/functional/hash/detail/hash_float_generic.hpp b/boost/functional/hash/detail/hash_float_generic.hpp
deleted file mode 100644
index 1278c2f626..0000000000
--- a/boost/functional/hash/detail/hash_float_generic.hpp
+++ /dev/null
@@ -1,91 +0,0 @@
-
-// Copyright 2005-2009 Daniel James.
-// Distributed under the Boost Software License, Version 1.0. (See accompanying
-// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-
-// A general purpose hash function for non-zero floating point values.
-
-#if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_GENERIC_HEADER)
-#define BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_GENERIC_HEADER
-
-#include <boost/functional/hash/detail/float_functions.hpp>
-#include <boost/integer/static_log2.hpp>
-#include <boost/functional/hash/detail/limits.hpp>
-
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
-#if defined(BOOST_MSVC)
-#pragma warning(push)
-#if BOOST_MSVC >= 1400
-#pragma warning(disable:6294) // Ill-defined for-loop: initial condition does
- // not satisfy test. Loop body not executed
-#endif
-#endif
-
-namespace boost
-{
- namespace hash_detail
- {
- inline void hash_float_combine(std::size_t& seed, std::size_t value)
- {
- seed ^= value + (seed<<6) + (seed>>2);
- }
-
- template <class T>
- inline std::size_t float_hash_impl2(T v)
- {
- boost::hash_detail::call_frexp<T> frexp;
- boost::hash_detail::call_ldexp<T> ldexp;
-
- int exp = 0;
-
- v = frexp(v, &exp);
-
- // A postive value is easier to hash, so combine the
- // sign with the exponent and use the absolute value.
- if(v < 0) {
- v = -v;
- exp += limits<T>::max_exponent -
- limits<T>::min_exponent;
- }
-
- v = ldexp(v, limits<std::size_t>::digits);
- std::size_t seed = static_cast<std::size_t>(v);
- v -= static_cast<T>(seed);
-
- // ceiling(digits(T) * log2(radix(T))/ digits(size_t)) - 1;
- std::size_t const length
- = (limits<T>::digits *
- boost::static_log2<limits<T>::radix>::value
- + limits<std::size_t>::digits - 1)
- / limits<std::size_t>::digits;
-
- for(std::size_t i = 0; i != length; ++i)
- {
- v = ldexp(v, limits<std::size_t>::digits);
- std::size_t part = static_cast<std::size_t>(v);
- v -= static_cast<T>(part);
- hash_float_combine(seed, part);
- }
-
- hash_float_combine(seed, exp);
-
- return seed;
- }
-
- template <class T>
- inline std::size_t float_hash_impl(T v)
- {
- typedef BOOST_DEDUCED_TYPENAME select_hash_type<T>::type type;
- return float_hash_impl2(static_cast<type>(v));
- }
- }
-}
-
-#if defined(BOOST_MSVC)
-#pragma warning(pop)
-#endif
-
-#endif
diff --git a/boost/functional/hash/detail/hash_float_x86.hpp b/boost/functional/hash/detail/hash_float_x86.hpp
deleted file mode 100644
index b39bb0d081..0000000000
--- a/boost/functional/hash/detail/hash_float_x86.hpp
+++ /dev/null
@@ -1,56 +0,0 @@
-
-// Copyright 2005-2009 Daniel James.
-// Distributed under the Boost Software License, Version 1.0. (See accompanying
-// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-
-// A non-portable hash function form non-zero floats on x86.
-//
-// Even if you're on an x86 platform, this might not work if their floating
-// point isn't set up as this expects. So this should only be used if it's
-// absolutely certain that it will work.
-
-#if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_X86_HEADER)
-#define BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_X86_HEADER
-
-#include <boost/cstdint.hpp>
-
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
-namespace boost
-{
- namespace hash_detail
- {
- inline void hash_float_combine(std::size_t& seed, std::size_t value)
- {
- seed ^= value + (seed<<6) + (seed>>2);
- }
-
- inline std::size_t float_hash_impl(float v)
- {
- boost::uint32_t* ptr = (boost::uint32_t*)&v;
- std::size_t seed = *ptr;
- return seed;
- }
-
- inline std::size_t float_hash_impl(double v)
- {
- boost::uint32_t* ptr = (boost::uint32_t*)&v;
- std::size_t seed = *ptr++;
- hash_float_combine(seed, *ptr);
- return seed;
- }
-
- inline std::size_t float_hash_impl(long double v)
- {
- boost::uint32_t* ptr = (boost::uint32_t*)&v;
- std::size_t seed = *ptr++;
- hash_float_combine(seed, *ptr++);
- hash_float_combine(seed, *(boost::uint16_t*)ptr);
- return seed;
- }
- }
-}
-
-#endif
diff --git a/boost/functional/hash/detail/limits.hpp b/boost/functional/hash/detail/limits.hpp
index f5b520ea9d..4a971a6ac2 100644
--- a/boost/functional/hash/detail/limits.hpp
+++ b/boost/functional/hash/detail/limits.hpp
@@ -9,8 +9,9 @@
#if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_LIMITS_HEADER)
#define BOOST_FUNCTIONAL_HASH_DETAIL_LIMITS_HEADER
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
+#include <boost/config.hpp>
+#if defined(BOOST_HAS_PRAGMA_ONCE)
+#pragma once
#endif
#include <boost/limits.hpp>
diff --git a/boost/functional/hash/extensions.hpp b/boost/functional/hash/extensions.hpp
index 4358736b26..eafaefe85d 100644
--- a/boost/functional/hash/extensions.hpp
+++ b/boost/functional/hash/extensions.hpp
@@ -13,23 +13,32 @@
#if !defined(BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP)
#define BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP
+#include <boost/config.hpp>
+#if defined(BOOST_HAS_PRAGMA_ONCE)
+#pragma once
+#endif
+
#include <boost/functional/hash/hash.hpp>
-#include <boost/functional/hash/detail/container_fwd_0x.hpp>
+#include <boost/detail/container_fwd.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/static_assert.hpp>
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
+#if !defined(BOOST_NO_CXX11_HDR_ARRAY)
+# include <array>
#endif
-#if defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
-#include <boost/type_traits/is_array.hpp>
+#if !defined(BOOST_NO_CXX11_HDR_TUPLE)
+# include <tuple>
#endif
-#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
-#include <boost/type_traits/is_const.hpp>
+#if !defined(BOOST_NO_CXX11_HDR_MEMORY)
+# include <memory>
+#endif
+
+#if defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
+#include <boost/type_traits/is_array.hpp>
#endif
namespace boost
@@ -149,7 +158,7 @@ namespace boost
}
}
-#if !defined(BOOST_NO_VARIADIC_TEMPLATES)
+#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <typename... T>
inline std::size_t hash_value(std::tuple<T...> const& v)
{
@@ -220,11 +229,7 @@ namespace boost
template <class Array>
struct inner
{
-#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
static std::size_t call(Array const& v)
-#else
- static std::size_t call(Array& v)
-#endif
{
const int size = sizeof(v) / sizeof(*v);
return boost::hash_range(v, v + size);
@@ -286,8 +291,6 @@ namespace boost
template <bool IsPointer>
struct hash_impl;
-#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
-
template <>
struct hash_impl<false>
{
@@ -308,58 +311,6 @@ namespace boost
#endif
};
};
-
-#else // Visual C++ 6.5
-
- // Visual C++ 6.5 has problems with nested member functions and
- // applying const to const types in templates. So we get this:
-
- template <bool IsConst>
- struct hash_impl_msvc
- {
- template <class T>
- struct inner
- : public std::unary_function<T, std::size_t>
- {
- std::size_t operator()(T const& val) const
- {
- return hash_detail::call_hash<T const>::call(val);
- }
-
- std::size_t operator()(T& val) const
- {
- return hash_detail::call_hash<T>::call(val);
- }
- };
- };
-
- template <>
- struct hash_impl_msvc<true>
- {
- template <class T>
- struct inner
- : public std::unary_function<T, std::size_t>
- {
- std::size_t operator()(T& val) const
- {
- return hash_detail::call_hash<T>::call(val);
- }
- };
- };
-
- template <class T>
- struct hash_impl_msvc2
- : public hash_impl_msvc<boost::is_const<T>::value>
- ::BOOST_NESTED_TEMPLATE inner<T> {};
-
- template <>
- struct hash_impl<false>
- {
- template <class T>
- struct inner : public hash_impl_msvc2<T> {};
- };
-
-#endif // Visual C++ 6.5
}
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
}
diff --git a/boost/functional/hash/hash.hpp b/boost/functional/hash/hash.hpp
index c179fab69a..3e5ab5bcf9 100644
--- a/boost/functional/hash/hash.hpp
+++ b/boost/functional/hash/hash.hpp
@@ -1,11 +1,17 @@
-// Copyright 2005-2009 Daniel James.
+// Copyright 2005-2014 Daniel James.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// Based on Peter Dimov's proposal
// http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf
// issue 6.18.
+//
+// This also contains public domain code from MurmurHash. From the
+// MurmurHash header:
+
+// MurmurHash3 was written by Austin Appleby, and is placed in the public
+// domain. The author hereby disclaims copyright to this source code.
#if !defined(BOOST_FUNCTIONAL_HASH_HASH_HPP)
#define BOOST_FUNCTIONAL_HASH_HASH_HPP
@@ -15,6 +21,10 @@
#include <boost/functional/hash/detail/hash_float.hpp>
#include <string>
#include <boost/limits.hpp>
+#include <boost/type_traits/is_enum.hpp>
+#include <boost/type_traits/is_integral.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/cstdint.hpp>
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
#include <boost/type_traits/is_pointer.hpp>
@@ -24,6 +34,17 @@
#include <typeindex>
#endif
+#if defined(BOOST_MSVC)
+#pragma warning(push)
+
+#if BOOST_MSVC >= 1400
+#pragma warning(disable:6295) // Ill-defined for-loop : 'unsigned int' values
+ // are always of range '0' to '4294967295'.
+ // Loop executes infinitely.
+#endif
+
+#endif
+
#if BOOST_WORKAROUND(__GNUC__, < 3) \
&& !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
#define BOOST_HASH_CHAR_TRAITS string_char_traits
@@ -31,6 +52,12 @@
#define BOOST_HASH_CHAR_TRAITS char_traits
#endif
+#if defined(_MSC_VER)
+# define BOOST_FUNCTIONAL_HASH_ROTL32(x, r) _rotl(x,r)
+#else
+# define BOOST_FUNCTIONAL_HASH_ROTL32(x, r) (x << r) | (x >> (32 - r))
+#endif
+
namespace boost
{
namespace hash_detail
@@ -38,8 +65,8 @@ namespace boost
struct enable_hash_value { typedef std::size_t type; };
template <typename T> struct basic_numbers {};
- template <typename T> struct long_numbers {};
- template <typename T> struct ulong_numbers {};
+ template <typename T> struct long_numbers;
+ template <typename T> struct ulong_numbers;
template <typename T> struct float_numbers {};
template <> struct basic_numbers<bool> :
@@ -68,6 +95,14 @@ namespace boost
boost::hash_detail::enable_hash_value {};
#endif
+ // long_numbers is defined like this to allow for separate
+ // specialization for long_long and int128_type, in case
+ // they conflict.
+ template <typename T> struct long_numbers2 {};
+ template <typename T> struct ulong_numbers2 {};
+ template <typename T> struct long_numbers : long_numbers2<T> {};
+ template <typename T> struct ulong_numbers : ulong_numbers2<T> {};
+
#if !defined(BOOST_NO_LONG_LONG)
template <> struct long_numbers<boost::long_long_type> :
boost::hash_detail::enable_hash_value {};
@@ -75,6 +110,13 @@ namespace boost
boost::hash_detail::enable_hash_value {};
#endif
+#if defined(BOOST_HAS_INT128)
+ template <> struct long_numbers2<boost::int128_type> :
+ boost::hash_detail::enable_hash_value {};
+ template <> struct ulong_numbers2<boost::uint128_type> :
+ boost::hash_detail::enable_hash_value {};
+#endif
+
template <> struct float_numbers<float> :
boost::hash_detail::enable_hash_value {};
template <> struct float_numbers<double> :
@@ -90,6 +132,10 @@ namespace boost
template <typename T>
typename boost::hash_detail::ulong_numbers<T>::type hash_value(T);
+ template <typename T>
+ typename boost::enable_if<boost::is_enum<T>, std::size_t>::type
+ hash_value(T);
+
#if !BOOST_WORKAROUND(__DMC__, <= 0x848)
template <class T> std::size_t hash_value(T* const&);
#else
@@ -159,6 +205,51 @@ namespace boost
return seed;
}
+
+ template <typename SizeT>
+ inline void hash_combine_impl(SizeT& seed, SizeT value)
+ {
+ seed ^= value + 0x9e3779b9 + (seed<<6) + (seed>>2);
+ }
+
+ template <typename SizeT>
+ inline void hash_combine_impl(boost::uint32_t& h1,
+ boost::uint32_t k1)
+ {
+ const uint32_t c1 = 0xcc9e2d51;
+ const uint32_t c2 = 0x1b873593;
+
+ k1 *= c1;
+ k1 = BOOST_FUNCTIONAL_HASH_ROTL32(k1,15);
+ k1 *= c2;
+
+ h1 ^= k1;
+ h1 = BOOST_FUNCTIONAL_HASH_ROTL32(h1,13);
+ h1 = h1*5+0xe6546b64;
+ }
+
+
+// Don't define 64-bit hash combine on platforms with 64 bit integers,
+// and also not for 32-bit gcc as it warns about the 64-bit constant.
+#if !defined(BOOST_NO_INT64_T) && \
+ !(defined(__GNUC__) && ULONG_MAX == 0xffffffff)
+
+ template <typename SizeT>
+ inline void hash_combine_impl(boost::uint64_t& h,
+ boost::uint64_t k)
+ {
+ const uint64_t m = UINT64_C(0xc6a4a7935bd1e995);
+ const int r = 47;
+
+ k *= m;
+ k ^= k >> r;
+ k *= m;
+
+ h ^= k;
+ h *= m;
+ }
+
+#endif // BOOST_NO_INT64_T
}
template <typename T>
@@ -179,6 +270,13 @@ namespace boost
return hash_detail::hash_value_unsigned(v);
}
+ template <typename T>
+ typename boost::enable_if<boost::is_enum<T>, std::size_t>::type
+ hash_value(T v)
+ {
+ return static_cast<std::size_t>(v);
+ }
+
// Implementation by Alberto Barbati and Dave Harris.
#if !BOOST_WORKAROUND(__DMC__, <= 0x848)
template <class T> std::size_t hash_value(T* const& v)
@@ -208,16 +306,11 @@ namespace boost
#endif
#endif
-#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
- template <class T>
- inline void hash_combine(std::size_t& seed, T& v)
-#else
template <class T>
inline void hash_combine(std::size_t& seed, T const& v)
-#endif
{
boost::hash<T> hasher;
- seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
+ return boost::hash_detail::hash_combine_impl(seed, hasher(v));
}
#if defined(BOOST_MSVC)
@@ -322,7 +415,6 @@ namespace boost
//
// These are undefined later.
-#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
#define BOOST_HASH_SPECIALIZE(type) \
template <> struct hash<type> \
: public std::unary_function<type, std::size_t> \
@@ -342,45 +434,6 @@ namespace boost
return boost::hash_value(v); \
} \
};
-#else
-#define BOOST_HASH_SPECIALIZE(type) \
- template <> struct hash<type> \
- : public std::unary_function<type, std::size_t> \
- { \
- std::size_t operator()(type v) const \
- { \
- return boost::hash_value(v); \
- } \
- }; \
- \
- template <> struct hash<const type> \
- : public std::unary_function<const type, std::size_t> \
- { \
- std::size_t operator()(const type v) const \
- { \
- return boost::hash_value(v); \
- } \
- };
-
-#define BOOST_HASH_SPECIALIZE_REF(type) \
- template <> struct hash<type> \
- : public std::unary_function<type, std::size_t> \
- { \
- std::size_t operator()(type const& v) const \
- { \
- return boost::hash_value(v); \
- } \
- }; \
- \
- template <> struct hash<const type> \
- : public std::unary_function<const type, std::size_t> \
- { \
- std::size_t operator()(type const& v) const \
- { \
- return boost::hash_value(v); \
- } \
- };
-#endif
BOOST_HASH_SPECIALIZE(bool)
BOOST_HASH_SPECIALIZE(char)
@@ -410,6 +463,11 @@ namespace boost
BOOST_HASH_SPECIALIZE(boost::ulong_long_type)
#endif
+#if defined(BOOST_HAS_INT128)
+ BOOST_HASH_SPECIALIZE(boost::int128_type)
+ BOOST_HASH_SPECIALIZE(boost::uint128_type)
+#endif
+
#if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX)
BOOST_HASH_SPECIALIZE(std::type_index)
#endif
@@ -483,6 +541,11 @@ namespace boost
}
#undef BOOST_HASH_CHAR_TRAITS
+#undef BOOST_FUNCTIONAL_HASH_ROTL32
+
+#if defined(BOOST_MSVC)
+#pragma warning(pop)
+#endif
#endif // BOOST_FUNCTIONAL_HASH_HASH_HPP
diff --git a/boost/functional/hash/hash_fwd.hpp b/boost/functional/hash/hash_fwd.hpp
index 1d51b07f2d..01fe012ed6 100644
--- a/boost/functional/hash/hash_fwd.hpp
+++ b/boost/functional/hash/hash_fwd.hpp
@@ -10,11 +10,11 @@
#if !defined(BOOST_FUNCTIONAL_HASH_FWD_HPP)
#define BOOST_FUNCTIONAL_HASH_FWD_HPP
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
+#include <boost/config.hpp>
+#if defined(BOOST_HAS_PRAGMA_ONCE)
+#pragma once
#endif
-#include <boost/config.hpp>
#include <cstddef>
#include <boost/detail/workaround.hpp>
@@ -22,11 +22,7 @@ namespace boost
{
template <class T> struct hash;
-#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
- template <class T> void hash_combine(std::size_t& seed, T& v);
-#else
template <class T> void hash_combine(std::size_t& seed, T const& v);
-#endif
template <class It> std::size_t hash_range(It, It);
template <class It> void hash_range(std::size_t&, It, It);