mirror of
https://github.com/boostorg/functional.git
synced 2025-08-01 21:44:28 +02:00
Merge new changes to unordered & hash.
- Unordered tests can run lightweight test or Boost.Test (at least theoretically). - Workaround Open BSD's incorrect numeric_limits. - Move the hash extensions in their own file. - Various small improvements to the unordered docs. - Fix some unordered examples. Merged revisions 43117-43837 via svnmerge from https://svn.boost.org/svn/boost/branches/unordered/trunk [SVN r43838]
This commit is contained in:
@@ -12,4 +12,15 @@ boostbook standalone : hash :
|
|||||||
<xsl:param>chunk.section.depth=2
|
<xsl:param>chunk.section.depth=2
|
||||||
<xsl:param>generate.section.toc.level=2
|
<xsl:param>generate.section.toc.level=2
|
||||||
<xsl:param>toc.section.depth=1
|
<xsl:param>toc.section.depth=1
|
||||||
<xsl:param>toc.max.depth=1 ;
|
<xsl:param>toc.max.depth=1
|
||||||
|
|
||||||
|
<dependency>css
|
||||||
|
<dependency>images
|
||||||
|
;
|
||||||
|
|
||||||
|
install css : [ glob $(BOOST_ROOT)/doc/src/*.css ]
|
||||||
|
: <location>html ;
|
||||||
|
install images : [ glob $(BOOST_ROOT)/doc/src/images/*.png ]
|
||||||
|
: <location>html/images ;
|
||||||
|
explicit css ;
|
||||||
|
explicit images ;
|
||||||
|
@@ -29,12 +29,12 @@ void float_tests(char const* name, T* = 0)
|
|||||||
std::cerr<<"\n"
|
std::cerr<<"\n"
|
||||||
<<"Testing " BOOST_STRINGIZE(HASH_NAMESPACE) "::hash<"<<name<<">\n"
|
<<"Testing " BOOST_STRINGIZE(HASH_NAMESPACE) "::hash<"<<name<<">\n"
|
||||||
<<"\n"
|
<<"\n"
|
||||||
<<"std::numeric_limits<T>::digits = "
|
<<"boost::hash_detail::limits<T>::digits = "
|
||||||
<<std::numeric_limits<T>::digits<<"\n"
|
<<boost::hash_detail::limits<T>::digits<<"\n"
|
||||||
<<"std::numeric_limits<int>::digits = "
|
<<"boost::hash_detail::limits<int>::digits = "
|
||||||
<<std::numeric_limits<int>::digits<<"\n"
|
<<boost::hash_detail::limits<int>::digits<<"\n"
|
||||||
<<"std::numeric_limits<std::size_t>::digits = "
|
<<"boost::hash_detail::limits<std::size_t>::digits = "
|
||||||
<<std::numeric_limits<std::size_t>::digits<<"\n"
|
<<boost::hash_detail::limits<std::size_t>::digits<<"\n"
|
||||||
<<"\n"
|
<<"\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -55,11 +55,11 @@ void float_tests(char const* name, T* = 0)
|
|||||||
#if defined(__BORLANDC__)
|
#if defined(__BORLANDC__)
|
||||||
std::cerr<<"Not running infinity checks on Borland, as it causes it to crash.\n";
|
std::cerr<<"Not running infinity checks on Borland, as it causes it to crash.\n";
|
||||||
#else
|
#else
|
||||||
if(std::numeric_limits<T>::has_infinity) {
|
if(boost::hash_detail::limits<T>::has_infinity) {
|
||||||
T infinity = -log(zero);
|
T infinity = -log(zero);
|
||||||
T infinity2 = (T) 1. / zero;
|
T infinity2 = (T) 1. / zero;
|
||||||
T infinity3 = (T) -1. / minus_zero;
|
T infinity3 = (T) -1. / minus_zero;
|
||||||
T infinity4 = std::numeric_limits<T>::infinity();
|
T infinity4 = boost::hash_detail::limits<T>::infinity();
|
||||||
|
|
||||||
T minus_infinity = log(zero);
|
T minus_infinity = log(zero);
|
||||||
T minus_infinity2 = (T) -1. / zero;
|
T minus_infinity2 = (T) -1. / zero;
|
||||||
@@ -89,26 +89,26 @@ void float_tests(char const* name, T* = 0)
|
|||||||
|
|
||||||
// This should really be 'has_denorm == denorm_present' but some
|
// This should really be 'has_denorm == denorm_present' but some
|
||||||
// compilers don't have 'denorm_present'. See also a later use.
|
// compilers don't have 'denorm_present'. See also a later use.
|
||||||
if(std::numeric_limits<T>::has_denorm) {
|
if(boost::hash_detail::limits<T>::has_denorm) {
|
||||||
if(x1(std::numeric_limits<T>::denorm_min()) == x1(infinity)) {
|
if(x1(boost::hash_detail::limits<T>::denorm_min()) == x1(infinity)) {
|
||||||
std::cerr<<"x1(denorm_min) == x1(infinity) == "<<x1(infinity)<<"\n";
|
std::cerr<<"x1(denorm_min) == x1(infinity) == "<<x1(infinity)<<"\n";
|
||||||
}
|
}
|
||||||
if(x1(std::numeric_limits<T>::denorm_min()) == x1(minus_infinity)) {
|
if(x1(boost::hash_detail::limits<T>::denorm_min()) == x1(minus_infinity)) {
|
||||||
std::cerr<<"x1(denorm_min) == x1(-infinity) == "<<x1(minus_infinity)<<"\n";
|
std::cerr<<"x1(denorm_min) == x1(-infinity) == "<<x1(minus_infinity)<<"\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(std::numeric_limits<T>::has_quiet_NaN) {
|
if(boost::hash_detail::limits<T>::has_quiet_NaN) {
|
||||||
if(x1(std::numeric_limits<T>::quiet_NaN()) == x1(infinity)) {
|
if(x1(boost::hash_detail::limits<T>::quiet_NaN()) == x1(infinity)) {
|
||||||
std::cerr<<"x1(quiet_NaN) == x1(infinity) == "<<x1(infinity)<<"\n";
|
std::cerr<<"x1(quiet_NaN) == x1(infinity) == "<<x1(infinity)<<"\n";
|
||||||
}
|
}
|
||||||
if(x1(std::numeric_limits<T>::quiet_NaN()) == x1(minus_infinity)) {
|
if(x1(boost::hash_detail::limits<T>::quiet_NaN()) == x1(minus_infinity)) {
|
||||||
std::cerr<<"x1(quiet_NaN) == x1(-infinity) == "<<x1(minus_infinity)<<"\n";
|
std::cerr<<"x1(quiet_NaN) == x1(-infinity) == "<<x1(minus_infinity)<<"\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
T max = (std::numeric_limits<T>::max)();
|
T max = (boost::hash_detail::limits<T>::max)();
|
||||||
T half_max = max / 2;
|
T half_max = max / 2;
|
||||||
T quarter_max = max / 4;
|
T quarter_max = max / 4;
|
||||||
T three_quarter_max = max - quarter_max;
|
T three_quarter_max = max - quarter_max;
|
||||||
@@ -142,50 +142,50 @@ void float_tests(char const* name, T* = 0)
|
|||||||
BOOST_TEST(x1(v2) == HASH_NAMESPACE::hash_value(v2));
|
BOOST_TEST(x1(v2) == HASH_NAMESPACE::hash_value(v2));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BOOST_TEST(x1(std::numeric_limits<T>::epsilon()) ==
|
BOOST_TEST(x1(boost::hash_detail::limits<T>::epsilon()) ==
|
||||||
HASH_NAMESPACE::hash_value(std::numeric_limits<T>::epsilon()));
|
HASH_NAMESPACE::hash_value(boost::hash_detail::limits<T>::epsilon()));
|
||||||
|
|
||||||
BOOST_TEST(std::numeric_limits<T>::epsilon() != (T) 0);
|
BOOST_TEST(boost::hash_detail::limits<T>::epsilon() != (T) 0);
|
||||||
if(x1(std::numeric_limits<T>::epsilon()) == x1((T) 0))
|
if(x1(boost::hash_detail::limits<T>::epsilon()) == x1((T) 0))
|
||||||
std::cerr<<"x1(epsilon) == x1(0) == "<<x1((T) 0)<<"\n";
|
std::cerr<<"x1(epsilon) == x1(0) == "<<x1((T) 0)<<"\n";
|
||||||
|
|
||||||
BOOST_TEST(-std::numeric_limits<T>::epsilon() != (T) 0);
|
BOOST_TEST(-boost::hash_detail::limits<T>::epsilon() != (T) 0);
|
||||||
if(x1(-std::numeric_limits<T>::epsilon()) == x1((T) 0))
|
if(x1(-boost::hash_detail::limits<T>::epsilon()) == x1((T) 0))
|
||||||
std::cerr<<"x1(-epsilon) == x1(0) == "<<x1((T) 0)<<"\n";
|
std::cerr<<"x1(-epsilon) == x1(0) == "<<x1((T) 0)<<"\n";
|
||||||
|
|
||||||
BOOST_TEST((T) 1 + std::numeric_limits<T>::epsilon() != (T) 1);
|
BOOST_TEST((T) 1 + boost::hash_detail::limits<T>::epsilon() != (T) 1);
|
||||||
if(x1((T) 1 + std::numeric_limits<T>::epsilon()) == x1((T) 1))
|
if(x1((T) 1 + boost::hash_detail::limits<T>::epsilon()) == x1((T) 1))
|
||||||
std::cerr<<"x1(1 + epsilon) == x1(1) == "<<x1((T) 1)<<"\n";
|
std::cerr<<"x1(1 + epsilon) == x1(1) == "<<x1((T) 1)<<"\n";
|
||||||
|
|
||||||
BOOST_TEST((T) 1 - std::numeric_limits<T>::epsilon() != (T) 1);
|
BOOST_TEST((T) 1 - boost::hash_detail::limits<T>::epsilon() != (T) 1);
|
||||||
if(x1((T) 1 - std::numeric_limits<T>::epsilon()) == x1((T) 1))
|
if(x1((T) 1 - boost::hash_detail::limits<T>::epsilon()) == x1((T) 1))
|
||||||
std::cerr<<"x1(1 - epsilon) == x1(1) == "<<x1((T) 1)<<"\n";
|
std::cerr<<"x1(1 - epsilon) == x1(1) == "<<x1((T) 1)<<"\n";
|
||||||
|
|
||||||
BOOST_TEST((T) -1 + std::numeric_limits<T>::epsilon() != (T) -1);
|
BOOST_TEST((T) -1 + boost::hash_detail::limits<T>::epsilon() != (T) -1);
|
||||||
if(x1((T) -1 + std::numeric_limits<T>::epsilon()) == x1((T) -1))
|
if(x1((T) -1 + boost::hash_detail::limits<T>::epsilon()) == x1((T) -1))
|
||||||
std::cerr<<"x1(-1 + epsilon) == x1(-1) == "<<x1((T) -1)<<"\n";
|
std::cerr<<"x1(-1 + epsilon) == x1(-1) == "<<x1((T) -1)<<"\n";
|
||||||
|
|
||||||
BOOST_TEST((T) -1 - std::numeric_limits<T>::epsilon() != (T) -1);
|
BOOST_TEST((T) -1 - boost::hash_detail::limits<T>::epsilon() != (T) -1);
|
||||||
if(x1((T) -1 - std::numeric_limits<T>::epsilon()) == x1((T) -1))
|
if(x1((T) -1 - boost::hash_detail::limits<T>::epsilon()) == x1((T) -1))
|
||||||
std::cerr<<"x1(-1 - epsilon) == x1(-1) == "<<x1((T) -1)<<"\n";
|
std::cerr<<"x1(-1 - epsilon) == x1(-1) == "<<x1((T) -1)<<"\n";
|
||||||
|
|
||||||
// As before.
|
// As before.
|
||||||
if(std::numeric_limits<T>::has_denorm) {
|
if(boost::hash_detail::limits<T>::has_denorm) {
|
||||||
if(x1(std::numeric_limits<T>::denorm_min()) == x1(zero)) {
|
if(x1(boost::hash_detail::limits<T>::denorm_min()) == x1(zero)) {
|
||||||
std::cerr<<"x1(denorm_min) == x1(zero) == "<<x1(zero)<<"\n";
|
std::cerr<<"x1(denorm_min) == x1(zero) == "<<x1(zero)<<"\n";
|
||||||
}
|
}
|
||||||
#if !BOOST_WORKAROUND(__DECCXX_VER,<70190006)
|
#if !BOOST_WORKAROUND(__DECCXX_VER,<70190006)
|
||||||
// The Tru64/CXX standard library prior to 7.1 contains a bug in the
|
// The Tru64/CXX standard library prior to 7.1 contains a bug in the
|
||||||
// specialization of std::numeric_limits::denorm_min() for long
|
// specialization of boost::hash_detail::limits::denorm_min() for long
|
||||||
// doubles which causes this test to fail.
|
// doubles which causes this test to fail.
|
||||||
if(x1(std::numeric_limits<T>::denorm_min()) !=
|
if(x1(boost::hash_detail::limits<T>::denorm_min()) !=
|
||||||
HASH_NAMESPACE::hash_value(std::numeric_limits<T>::denorm_min()))
|
HASH_NAMESPACE::hash_value(boost::hash_detail::limits<T>::denorm_min()))
|
||||||
{
|
{
|
||||||
std::cerr<<"x1(std::numeric_limits<T>::denorm_min()) = "
|
std::cerr<<"x1(boost::hash_detail::limits<T>::denorm_min()) = "
|
||||||
<< x1(std::numeric_limits<T>::denorm_min())
|
<< x1(boost::hash_detail::limits<T>::denorm_min())
|
||||||
<< "\nhash_value(std::numeric_limits<T>::denorm_min()) = "
|
<< "\nhash_value(boost::hash_detail::limits<T>::denorm_min()) = "
|
||||||
<< HASH_NAMESPACE::hash_value(
|
<< HASH_NAMESPACE::hash_value(
|
||||||
std::numeric_limits<T>::denorm_min())
|
boost::hash_detail::limits<T>::denorm_min())
|
||||||
<< "\nx1(0) = "<<x1(0)<<"\n";
|
<< "\nx1(0) = "<<x1(0)<<"\n";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -193,12 +193,12 @@ void float_tests(char const* name, T* = 0)
|
|||||||
|
|
||||||
// NaN also causes borland to crash.
|
// NaN also causes borland to crash.
|
||||||
#if !defined(__BORLANDC__)
|
#if !defined(__BORLANDC__)
|
||||||
if(std::numeric_limits<T>::has_quiet_NaN) {
|
if(boost::hash_detail::limits<T>::has_quiet_NaN) {
|
||||||
if(x1(std::numeric_limits<T>::quiet_NaN()) == x1(1.0)) {
|
if(x1(boost::hash_detail::limits<T>::quiet_NaN()) == x1(1.0)) {
|
||||||
std::cerr<<"x1(quiet_NaN) == x1(1.0) == "<<x1(1.0)<<"\n";
|
std::cerr<<"x1(quiet_NaN) == x1(1.0) == "<<x1(1.0)<<"\n";
|
||||||
}
|
}
|
||||||
BOOST_TEST(x1(std::numeric_limits<T>::quiet_NaN()) ==
|
BOOST_TEST(x1(boost::hash_detail::limits<T>::quiet_NaN()) ==
|
||||||
HASH_NAMESPACE::hash_value(std::numeric_limits<T>::quiet_NaN()));
|
HASH_NAMESPACE::hash_value(boost::hash_detail::limits<T>::quiet_NaN()));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,7 @@
|
|||||||
template <class T>
|
template <class T>
|
||||||
void numeric_test(T*)
|
void numeric_test(T*)
|
||||||
{
|
{
|
||||||
typedef std::numeric_limits<T> limits;
|
typedef boost::hash_detail::limits<T> limits;
|
||||||
|
|
||||||
compile_time_tests((T*) 0);
|
compile_time_tests((T*) 0);
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ void numeric_test(T*)
|
|||||||
|
|
||||||
if (limits::is_integer)
|
if (limits::is_integer)
|
||||||
{
|
{
|
||||||
if(limits::is_signed || limits::digits <= std::numeric_limits<std::size_t>::digits)
|
if(limits::is_signed || limits::digits <= boost::hash_detail::limits<std::size_t>::digits)
|
||||||
BOOST_TEST(HASH_NAMESPACE::hash_value(T(-5)) == (std::size_t)T(-5));
|
BOOST_TEST(HASH_NAMESPACE::hash_value(T(-5)) == (std::size_t)T(-5));
|
||||||
BOOST_TEST(HASH_NAMESPACE::hash_value(T(0)) == (std::size_t)T(0u));
|
BOOST_TEST(HASH_NAMESPACE::hash_value(T(0)) == (std::size_t)T(0u));
|
||||||
BOOST_TEST(HASH_NAMESPACE::hash_value(T(10)) == (std::size_t)T(10u));
|
BOOST_TEST(HASH_NAMESPACE::hash_value(T(10)) == (std::size_t)T(10u));
|
||||||
@@ -67,7 +67,7 @@ void numeric_test(T*)
|
|||||||
template <class T>
|
template <class T>
|
||||||
void limits_test(T*)
|
void limits_test(T*)
|
||||||
{
|
{
|
||||||
typedef std::numeric_limits<T> limits;
|
typedef boost::hash_detail::limits<T> limits;
|
||||||
|
|
||||||
if(limits::is_specialized)
|
if(limits::is_specialized)
|
||||||
{
|
{
|
||||||
@@ -98,7 +98,7 @@ void limits_test(T*)
|
|||||||
template <class T>
|
template <class T>
|
||||||
void poor_quality_tests(T*)
|
void poor_quality_tests(T*)
|
||||||
{
|
{
|
||||||
typedef std::numeric_limits<T> limits;
|
typedef boost::hash_detail::limits<T> limits;
|
||||||
|
|
||||||
HASH_NAMESPACE::hash<T> x1;
|
HASH_NAMESPACE::hash<T> x1;
|
||||||
HASH_NAMESPACE::hash<T> x2;
|
HASH_NAMESPACE::hash<T> x2;
|
||||||
|
@@ -54,10 +54,43 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// On OpenBSD, numeric_limits is not reliable for long doubles, but
|
||||||
|
// the macros defined in <float.h> are.
|
||||||
|
|
||||||
|
#if defined(__OpenBSD__)
|
||||||
|
#include <float.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
namespace hash_detail
|
namespace hash_detail
|
||||||
{
|
{
|
||||||
|
template <class T>
|
||||||
|
struct limits : std::numeric_limits<T> {};
|
||||||
|
|
||||||
|
#if defined(__OpenBSD__)
|
||||||
|
template <>
|
||||||
|
struct limits<long double>
|
||||||
|
: std::numeric_limits<long double>
|
||||||
|
{
|
||||||
|
static long double epsilon() {
|
||||||
|
return LDBL_EPSILON;
|
||||||
|
}
|
||||||
|
|
||||||
|
static long double (max)() {
|
||||||
|
return LDBL_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
static long double (min)() {
|
||||||
|
return LDBL_MIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_STATIC_CONSTANT(int, digits = LDBL_MANT_DIG);
|
||||||
|
BOOST_STATIC_CONSTANT(int, max_exponent = LDBL_MAX_EXP);
|
||||||
|
BOOST_STATIC_CONSTANT(int, min_exponent = LDBL_MIN_EXP);
|
||||||
|
};
|
||||||
|
#endif // __OpenBSD__
|
||||||
|
|
||||||
inline void hash_float_combine(std::size_t& seed, std::size_t value)
|
inline void hash_float_combine(std::size_t& seed, std::size_t value)
|
||||||
{
|
{
|
||||||
seed ^= value + (seed<<6) + (seed>>2);
|
seed ^= value + (seed<<6) + (seed>>2);
|
||||||
@@ -102,29 +135,28 @@ namespace boost
|
|||||||
// sign with the exponent.
|
// sign with the exponent.
|
||||||
if(v < 0) {
|
if(v < 0) {
|
||||||
v = -v;
|
v = -v;
|
||||||
exp += std::numeric_limits<T>::max_exponent -
|
exp += limits<T>::max_exponent -
|
||||||
std::numeric_limits<T>::min_exponent;
|
limits<T>::min_exponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The result of frexp is always between 0.5 and 1, so its
|
// The result of frexp is always between 0.5 and 1, so its
|
||||||
// top bit will always be 1. Subtract by 0.5 to remove that.
|
// top bit will always be 1. Subtract by 0.5 to remove that.
|
||||||
v -= T(0.5);
|
v -= T(0.5);
|
||||||
v = boost::hash_detail::call_ldexp(v,
|
v = boost::hash_detail::call_ldexp(v,
|
||||||
std::numeric_limits<std::size_t>::digits + 1);
|
limits<std::size_t>::digits + 1);
|
||||||
std::size_t seed = static_cast<std::size_t>(v);
|
std::size_t seed = static_cast<std::size_t>(v);
|
||||||
v -= seed;
|
v -= seed;
|
||||||
|
|
||||||
// ceiling(digits(T) * log2(radix(T))/ digits(size_t)) - 1;
|
// ceiling(digits(T) * log2(radix(T))/ digits(size_t)) - 1;
|
||||||
std::size_t const length
|
std::size_t const length
|
||||||
= (std::numeric_limits<T>::digits *
|
= (limits<T>::digits *
|
||||||
boost::static_log2<std::numeric_limits<T>::radix>::value
|
boost::static_log2<limits<T>::radix>::value - 1)
|
||||||
- 1)
|
/ limits<std::size_t>::digits;
|
||||||
/ std::numeric_limits<std::size_t>::digits;
|
|
||||||
|
|
||||||
for(std::size_t i = 0; i != length; ++i)
|
for(std::size_t i = 0; i != length; ++i)
|
||||||
{
|
{
|
||||||
v = boost::hash_detail::call_ldexp(v,
|
v = boost::hash_detail::call_ldexp(v,
|
||||||
std::numeric_limits<std::size_t>::digits);
|
limits<std::size_t>::digits);
|
||||||
std::size_t part = static_cast<std::size_t>(v);
|
std::size_t part = static_cast<std::size_t>(v);
|
||||||
v -= part;
|
v -= part;
|
||||||
hash_float_combine(seed, part);
|
hash_float_combine(seed, part);
|
||||||
|
@@ -8,3 +8,4 @@
|
|||||||
// issue 6.18.
|
// issue 6.18.
|
||||||
|
|
||||||
#include <boost/functional/hash/hash.hpp>
|
#include <boost/functional/hash/hash.hpp>
|
||||||
|
|
||||||
|
182
include/boost/functional/hash/extensions.hpp
Normal file
182
include/boost/functional/hash/extensions.hpp
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
|
||||||
|
// Copyright 2005-2007 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.
|
||||||
|
|
||||||
|
#if !defined(BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
|
||||||
|
#if defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <bool IsArray>
|
||||||
|
struct call_hash_impl
|
||||||
|
{
|
||||||
|
template <class T>
|
||||||
|
struct inner
|
||||||
|
{
|
||||||
|
static std::size_t call(T const& v)
|
||||||
|
{
|
||||||
|
using namespace boost;
|
||||||
|
return hash_value(v);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct call_hash_impl<true>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct call_hash
|
||||||
|
: public call_hash_impl<boost::is_array<T>::value>
|
||||||
|
::BOOST_NESTED_TEMPLATE inner<T>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
|
|
||||||
|
template <class T> struct hash
|
||||||
|
: std::unary_function<T, std::size_t>
|
||||||
|
{
|
||||||
|
#if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
||||||
|
std::size_t operator()(T const& val) const
|
||||||
|
{
|
||||||
|
return hash_value(val);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
std::size_t operator()(T const& val) const
|
||||||
|
{
|
||||||
|
return hash_detail::call_hash<T>::call(val);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#if BOOST_WORKAROUND(__DMC__, <= 0x848)
|
||||||
|
template <class T, unsigned int n> struct hash<T[n]>
|
||||||
|
: std::unary_function<T[n], std::size_t>
|
||||||
|
{
|
||||||
|
std::size_t operator()(const T* val) const
|
||||||
|
{
|
||||||
|
return boost::hash_range(val, val+n);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
|
|
||||||
|
// On compilers without partial specialization, boost::hash<T>
|
||||||
|
// has already been declared to deal with pointers, so just
|
||||||
|
// need to supply the non-pointer version.
|
||||||
|
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <bool IsPointer>
|
||||||
|
struct hash_impl;
|
||||||
|
|
||||||
|
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct hash_impl<false>
|
||||||
|
{
|
||||||
|
template <class T>
|
||||||
|
struct inner
|
||||||
|
: std::unary_function<T, std::size_t>
|
||||||
|
{
|
||||||
|
#if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
||||||
|
std::size_t operator()(T const& val) const
|
||||||
|
{
|
||||||
|
return hash_value(val);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
std::size_t operator()(T const& val) const
|
||||||
|
{
|
||||||
|
return hash_detail::call_hash<T>::call(val);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
#else // Visual C++ 6.5
|
||||||
|
|
||||||
|
// There's probably a more elegant way to Visual C++ 6.5 to work
|
||||||
|
// but I don't know what it is.
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@@ -518,176 +518,12 @@ namespace boost
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // BOOST_FUNCTIONAL_HASH_HASH_HPP
|
#endif // BOOST_FUNCTIONAL_HASH_HASH_HPP
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
// Include this outside of the include guards in case the file is included
|
||||||
|
// twice - once with BOOST_HASH_NO_EXTENSIONS defined, and then with it
|
||||||
|
// undefined.
|
||||||
|
|
||||||
#if !defined(BOOST_HASH_NO_EXTENSIONS) \
|
#if !defined(BOOST_HASH_NO_EXTENSIONS) \
|
||||||
&& !defined(BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP)
|
&& !defined(BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP)
|
||||||
#define BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP
|
#include <boost/functional/hash/extensions.hpp>
|
||||||
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
|
|
||||||
#if defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
|
||||||
namespace hash_detail
|
|
||||||
{
|
|
||||||
template <bool IsArray>
|
|
||||||
struct call_hash_impl
|
|
||||||
{
|
|
||||||
template <class T>
|
|
||||||
struct inner
|
|
||||||
{
|
|
||||||
static std::size_t call(T const& v)
|
|
||||||
{
|
|
||||||
using namespace boost;
|
|
||||||
return hash_value(v);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct call_hash_impl<true>
|
|
||||||
{
|
|
||||||
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
|
#endif
|
||||||
{
|
|
||||||
const int size = sizeof(v) / sizeof(*v);
|
|
||||||
return boost::hash_range(v, v + size);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
struct call_hash
|
|
||||||
: public call_hash_impl<boost::is_array<T>::value>
|
|
||||||
::BOOST_NESTED_TEMPLATE inner<T>
|
|
||||||
{
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
|
||||||
|
|
||||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
|
||||||
|
|
||||||
template <class T> struct hash
|
|
||||||
: std::unary_function<T, std::size_t>
|
|
||||||
{
|
|
||||||
#if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
|
||||||
std::size_t operator()(T const& val) const
|
|
||||||
{
|
|
||||||
return hash_value(val);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
std::size_t operator()(T const& val) const
|
|
||||||
{
|
|
||||||
return hash_detail::call_hash<T>::call(val);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
#if BOOST_WORKAROUND(__DMC__, <= 0x848)
|
|
||||||
template <class T, unsigned int n> struct hash<T[n]>
|
|
||||||
: std::unary_function<T[n], std::size_t>
|
|
||||||
{
|
|
||||||
std::size_t operator()(const T* val) const
|
|
||||||
{
|
|
||||||
return boost::hash_range(val, val+n);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
|
||||||
|
|
||||||
// On compilers without partial specialization, boost::hash<T>
|
|
||||||
// has already been declared to deal with pointers, so just
|
|
||||||
// need to supply the non-pointer version.
|
|
||||||
|
|
||||||
namespace hash_detail
|
|
||||||
{
|
|
||||||
template <bool IsPointer>
|
|
||||||
struct hash_impl;
|
|
||||||
|
|
||||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct hash_impl<false>
|
|
||||||
{
|
|
||||||
template <class T>
|
|
||||||
struct inner
|
|
||||||
: std::unary_function<T, std::size_t>
|
|
||||||
{
|
|
||||||
#if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
|
||||||
std::size_t operator()(T const& val) const
|
|
||||||
{
|
|
||||||
return hash_value(val);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
std::size_t operator()(T const& val) const
|
|
||||||
{
|
|
||||||
return hash_detail::call_hash<T>::call(val);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
#else // Visual C++ 6.5
|
|
||||||
|
|
||||||
// There's probably a more elegant way to Visual C++ 6.5 to work
|
|
||||||
// but I don't know what it is.
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user