ndnboost: Include boost::iostreams for internal use.
diff --git a/include/ndnboost/functional/hash.hpp b/include/ndnboost/functional/hash.hpp
new file mode 100644
index 0000000..bcc68bc
--- /dev/null
+++ b/include/ndnboost/functional/hash.hpp
@@ -0,0 +1,7 @@
+
+// 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)
+
+#include <ndnboost/functional/hash/hash.hpp>
+
diff --git a/include/ndnboost/functional/hash/detail/float_functions.hpp b/include/ndnboost/functional/hash/detail/float_functions.hpp
new file mode 100644
index 0000000..131ab62
--- /dev/null
+++ b/include/ndnboost/functional/hash/detail/float_functions.hpp
@@ -0,0 +1,336 @@
+
+// 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)
+
+#if !defined(NDNBOOST_FUNCTIONAL_HASH_DETAIL_FLOAT_FUNCTIONS_HPP)
+#define NDNBOOST_FUNCTIONAL_HASH_DETAIL_FLOAT_FUNCTIONS_HPP
+
+#include <ndnboost/config.hpp>
+#include <ndnboost/config/no_tr1/cmath.hpp>
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+// Set NDNBOOST_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 NDNBOOST_HASH_CONFORMANT_FLOATS 0
+#elif defined(__LIBCOMO__)
+# define NDNBOOST_HASH_CONFORMANT_FLOATS 0
+#elif defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER)
+// Rogue Wave library:
+# define NDNBOOST_HASH_CONFORMANT_FLOATS 0
+#elif defined(_LIBCPP_VERSION)
+// libc++
+# define NDNBOOST_HASH_CONFORMANT_FLOATS 1
+#elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
+// GNU libstdc++ 3
+# if defined(__GNUC__) && __GNUC__ >= 4
+# define NDNBOOST_HASH_CONFORMANT_FLOATS 1
+# else
+# define NDNBOOST_HASH_CONFORMANT_FLOATS 0
+# endif
+#elif defined(__STL_CONFIG_H)
+// generic SGI STL
+# define NDNBOOST_HASH_CONFORMANT_FLOATS 0
+#elif defined(__MSL_CPP__)
+// MSL standard lib:
+# define NDNBOOST_HASH_CONFORMANT_FLOATS 0
+#elif defined(__IBMCPP__)
+// VACPP std lib (probably conformant for much earlier version).
+# if __IBMCPP__ >= 1210
+# define NDNBOOST_HASH_CONFORMANT_FLOATS 1
+# else
+# define NDNBOOST_HASH_CONFORMANT_FLOATS 0
+# endif
+#elif defined(MSIPL_COMPILE_H)
+// Modena C++ standard library
+# define NDNBOOST_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 NDNBOOST_HASH_CONFORMANT_FLOATS 1
+# else
+# define NDNBOOST_HASH_CONFORMANT_FLOATS 0
+# endif
+#else
+# define NDNBOOST_HASH_CONFORMANT_FLOATS 0
+#endif
+
+#if NDNBOOST_HASH_CONFORMANT_FLOATS
+
+// The standard library is known to be compliant, so don't use the
+// configuration mechanism.
+
+namespace ndnboost {
+ 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 // NDNBOOST_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
+// float functions (frexpf, frexpl, etc.) are available.
+//
+// The following tries to automatically detect which are available.
+
+namespace ndnboost {
+ namespace hash_detail {
+
+ // Returned by dummy versions of the float functions.
+
+ struct not_found {
+ // Implicitly convertible to float and long double in order to avoid
+ // a compile error when the dummy float functions are used.
+
+ inline operator float() const { return 0; }
+ inline operator long double() const { return 0; }
+ };
+
+ // A type for detecting the return type of functions.
+
+ template <typename T> struct is;
+ template <> struct is<float> { char x[10]; };
+ template <> struct is<double> { char x[20]; };
+ template <> struct is<long double> { char x[30]; };
+ template <> struct is<ndnboost::hash_detail::not_found> { char x[40]; };
+
+ // Used to convert the return type of a function to a type for sizeof.
+
+ template <typename T> is<T> float_type(T);
+
+ // call_ldexp
+ //
+ // This will get specialized for float and long double
+
+ template <typename Float> struct call_ldexp
+ {
+ typedef double float_type;
+
+ inline double operator()(double a, int b) const
+ {
+ using namespace std;
+ return ldexp(a, b);
+ }
+ };
+
+ // call_frexp
+ //
+ // This will get specialized for float and long double
+
+ template <typename Float> struct call_frexp
+ {
+ typedef double float_type;
+
+ inline double operator()(double a, int* b) const
+ {
+ using namespace std;
+ return frexp(a, b);
+ }
+ };
+ }
+}
+
+// A namespace for dummy functions to detect when the actual function we want
+// isn't available. ldexpl, ldexpf etc. might be added tby the macros below.
+//
+// AFAICT these have to be outside of the boost namespace, as if they're in
+// the boost namespace they'll always be preferable to any other function
+// (since the arguments are built in types, ADL can't be used).
+
+namespace ndnboost_hash_detect_float_functions {
+ template <class Float> ndnboost::hash_detail::not_found ldexp(Float, int);
+ template <class Float> ndnboost::hash_detail::not_found frexp(Float, int*);
+}
+
+// Macros for generating specializations of call_ldexp and call_frexp.
+//
+// check_cpp and check_c99 check if the C++ or C99 functions are available.
+//
+// Then the call_* functions select an appropriate implementation.
+//
+// I used c99_func in a few places just to get a unique name.
+//
+// Important: when using 'using namespace' at namespace level, include as
+// little as possible in that namespace, as Visual C++ has an odd bug which
+// can cause the namespace to be imported at the global level. This seems to
+// happen mainly when there's a template in the same namesapce.
+
+#define NDNBOOST_HASH_CALL_FLOAT_FUNC(cpp_func, c99_func, type1, type2) \
+namespace ndnboost_hash_detect_float_functions { \
+ template <class Float> \
+ ndnboost::hash_detail::not_found c99_func(Float, type2); \
+} \
+ \
+namespace ndnboost { \
+ namespace hash_detail { \
+ namespace c99_func##_detect { \
+ using namespace std; \
+ using namespace ndnboost_hash_detect_float_functions; \
+ \
+ struct check { \
+ static type1 x; \
+ static type2 y; \
+ NDNBOOST_STATIC_CONSTANT(bool, cpp = \
+ sizeof(float_type(cpp_func(x,y))) \
+ == sizeof(is<type1>)); \
+ NDNBOOST_STATIC_CONSTANT(bool, c99 = \
+ sizeof(float_type(c99_func(x,y))) \
+ == sizeof(is<type1>)); \
+ }; \
+ } \
+ \
+ template <bool x> \
+ struct call_c99_##c99_func : \
+ ndnboost::hash_detail::call_##cpp_func<double> {}; \
+ \
+ template <> \
+ struct call_c99_##c99_func<true> { \
+ typedef type1 float_type; \
+ \
+ template <typename T> \
+ inline type1 operator()(type1 a, T b) const \
+ { \
+ using namespace std; \
+ return c99_func(a, b); \
+ } \
+ }; \
+ \
+ template <bool x> \
+ struct call_cpp_##c99_func : \
+ call_c99_##c99_func< \
+ ::ndnboost::hash_detail::c99_func##_detect::check::c99 \
+ > {}; \
+ \
+ template <> \
+ struct call_cpp_##c99_func<true> { \
+ typedef type1 float_type; \
+ \
+ template <typename T> \
+ inline type1 operator()(type1 a, T b) const \
+ { \
+ using namespace std; \
+ return cpp_func(a, b); \
+ } \
+ }; \
+ \
+ template <> \
+ struct call_##cpp_func<type1> : \
+ call_cpp_##c99_func< \
+ ::ndnboost::hash_detail::c99_func##_detect::check::cpp \
+ > {}; \
+ } \
+}
+
+#define NDNBOOST_HASH_CALL_FLOAT_MACRO(cpp_func, c99_func, type1, type2) \
+namespace ndnboost { \
+ namespace hash_detail { \
+ \
+ template <> \
+ struct call_##cpp_func<type1> { \
+ typedef type1 float_type; \
+ inline type1 operator()(type1 x, type2 y) const { \
+ return c99_func(x, y); \
+ } \
+ }; \
+ } \
+}
+
+#if defined(ldexpf)
+NDNBOOST_HASH_CALL_FLOAT_MACRO(ldexp, ldexpf, float, int)
+#else
+NDNBOOST_HASH_CALL_FLOAT_FUNC(ldexp, ldexpf, float, int)
+#endif
+
+#if defined(ldexpl)
+NDNBOOST_HASH_CALL_FLOAT_MACRO(ldexp, ldexpl, long double, int)
+#else
+NDNBOOST_HASH_CALL_FLOAT_FUNC(ldexp, ldexpl, long double, int)
+#endif
+
+#if defined(frexpf)
+NDNBOOST_HASH_CALL_FLOAT_MACRO(frexp, frexpf, float, int*)
+#else
+NDNBOOST_HASH_CALL_FLOAT_FUNC(frexp, frexpf, float, int*)
+#endif
+
+#if defined(frexpl)
+NDNBOOST_HASH_CALL_FLOAT_MACRO(frexp, frexpl, long double, int*)
+#else
+NDNBOOST_HASH_CALL_FLOAT_FUNC(frexp, frexpl, long double, int*)
+#endif
+
+#undef NDNBOOST_HASH_CALL_FLOAT_MACRO
+#undef NDNBOOST_HASH_CALL_FLOAT_FUNC
+
+
+namespace ndnboost
+{
+ namespace hash_detail
+ {
+ template <typename Float1, typename Float2>
+ struct select_hash_type_impl {
+ typedef double type;
+ };
+
+ template <>
+ struct select_hash_type_impl<float, float> {
+ typedef float type;
+ };
+
+ template <>
+ struct select_hash_type_impl<long double, long double> {
+ typedef long double type;
+ };
+
+
+ // select_hash_type
+ //
+ // If there is support for a particular floating point type, use that
+ // otherwise use double (there's always support for double).
+
+ template <typename Float>
+ struct select_hash_type : select_hash_type_impl<
+ NDNBOOST_DEDUCED_TYPENAME call_ldexp<Float>::float_type,
+ NDNBOOST_DEDUCED_TYPENAME call_frexp<Float>::float_type
+ > {};
+ }
+}
+
+#endif // NDNBOOST_HASH_CONFORMANT_FLOATS
+
+#endif
diff --git a/include/ndnboost/functional/hash/detail/hash_float.hpp b/include/ndnboost/functional/hash/detail/hash_float.hpp
new file mode 100644
index 0000000..76873ae
--- /dev/null
+++ b/include/ndnboost/functional/hash/detail/hash_float.hpp
@@ -0,0 +1,277 @@
+
+// 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(NDNBOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_HEADER)
+#define NDNBOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_HEADER
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <ndnboost/config.hpp>
+#include <ndnboost/functional/hash/detail/float_functions.hpp>
+#include <ndnboost/functional/hash/detail/limits.hpp>
+#include <ndnboost/utility/enable_if.hpp>
+#include <ndnboost/integer/static_log2.hpp>
+#include <ndnboost/cstdint.hpp>
+#include <ndnboost/assert.hpp>
+#include <ndnboost/limits.hpp>
+#include <cstring>
+
+#if defined(NDNBOOST_MSVC)
+#pragma warning(push)
+#if NDNBOOST_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?
+
+// STLport
+#if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
+#define NDNBOOST_HASH_USE_FPCLASSIFY 0
+
+// GNU libstdc++ 3
+#elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
+# if (defined(__USE_ISOC99) || defined(_GLIBCXX_USE_C99_MATH)) && \
+ !(defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
+# define NDNBOOST_HASH_USE_FPCLASSIFY 1
+# else
+# define NDNBOOST_HASH_USE_FPCLASSIFY 0
+# endif
+
+// Everything else
+#else
+# define NDNBOOST_HASH_USE_FPCLASSIFY 0
+#endif
+
+namespace ndnboost
+{
+ 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>
+ inline std::size_t float_hash_impl(Float v,
+ NDNBOOST_DEDUCED_TYPENAME ndnboost::enable_if_c<
+ std::numeric_limits<Float>::is_iec559 &&
+ std::numeric_limits<Float>::digits == 24 &&
+ std::numeric_limits<Float>::radix == 2 &&
+ std::numeric_limits<Float>::max_exponent == 128,
+ int>::type
+ )
+ {
+ return hash_binary((char*) &v, 4);
+ }
+
+
+ template <typename Float>
+ inline std::size_t float_hash_impl(Float v,
+ NDNBOOST_DEDUCED_TYPENAME ndnboost::enable_if_c<
+ std::numeric_limits<Float>::is_iec559 &&
+ std::numeric_limits<Float>::digits == 53 &&
+ std::numeric_limits<Float>::radix == 2 &&
+ std::numeric_limits<Float>::max_exponent == 1024,
+ int>::type
+ )
+ {
+ return hash_binary((char*) &v, 8);
+ }
+
+ template <typename Float>
+ inline std::size_t float_hash_impl(Float v,
+ NDNBOOST_DEDUCED_TYPENAME ndnboost::enable_if_c<
+ std::numeric_limits<Float>::is_iec559 &&
+ std::numeric_limits<Float>::digits == 64 &&
+ std::numeric_limits<Float>::radix == 2 &&
+ std::numeric_limits<Float>::max_exponent == 16384,
+ int>::type
+ )
+ {
+ return hash_binary((char*) &v, 10);
+ }
+
+ template <typename Float>
+ inline std::size_t float_hash_impl(Float v,
+ NDNBOOST_DEDUCED_TYPENAME ndnboost::enable_if_c<
+ std::numeric_limits<Float>::is_iec559 &&
+ std::numeric_limits<Float>::digits == 113 &&
+ std::numeric_limits<Float>::radix == 2 &&
+ std::numeric_limits<Float>::max_exponent == 16384,
+ int>::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)
+ {
+ ndnboost::hash_detail::call_frexp<T> frexp;
+ ndnboost::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 *
+ ndnboost::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(NDNBOOST_HASH_DETAIL_TEST_WITHOUT_GENERIC)
+ template <class T>
+ inline std::size_t float_hash_impl(T v, ...)
+ {
+ typedef NDNBOOST_DEDUCED_TYPENAME select_hash_type<T>::type type;
+ return float_hash_impl2(static_cast<type>(v));
+ }
+#endif
+ }
+}
+
+#if NDNBOOST_HASH_USE_FPCLASSIFY
+
+#include <ndnboost/config/no_tr1/cmath.hpp>
+
+namespace ndnboost
+{
+ namespace hash_detail
+ {
+ template <class T>
+ inline std::size_t float_hash_value(T v)
+ {
+#if defined(fpclassify)
+ switch (fpclassify(v))
+#elif NDNBOOST_HASH_CONFORMANT_FLOATS
+ switch (std::fpclassify(v))
+#else
+ using namespace std;
+ switch (fpclassify(v))
+#endif
+ {
+ case FP_ZERO:
+ return 0;
+ case FP_INFINITE:
+ return (std::size_t)(v > 0 ? -1 : -2);
+ case FP_NAN:
+ return (std::size_t)(-3);
+ case FP_NORMAL:
+ case FP_SUBNORMAL:
+ return float_hash_impl(v, 0);
+ default:
+ NDNBOOST_ASSERT(0);
+ return 0;
+ }
+ }
+ }
+}
+
+#else // !NDNBOOST_HASH_USE_FPCLASSIFY
+
+namespace ndnboost
+{
+ namespace hash_detail
+ {
+ template <class T>
+ inline bool is_zero(T v)
+ {
+#if !defined(__GNUC__)
+ return v == 0;
+#else
+ // GCC's '-Wfloat-equal' will complain about comparing
+ // v to 0, but because it disables warnings for system
+ // headers it won't complain if you use std::equal_to to
+ // compare with 0. Resulting in this silliness:
+ return std::equal_to<T>()(v, 0);
+#endif
+ }
+
+ template <class T>
+ inline std::size_t float_hash_value(T v)
+ {
+ return ndnboost::hash_detail::is_zero(v) ? 0 : float_hash_impl(v, 0);
+ }
+ }
+}
+
+#endif // NDNBOOST_HASH_USE_FPCLASSIFY
+
+#undef NDNBOOST_HASH_USE_FPCLASSIFY
+
+#if defined(NDNBOOST_MSVC)
+#pragma warning(pop)
+#endif
+
+#endif
diff --git a/include/ndnboost/functional/hash/detail/limits.hpp b/include/ndnboost/functional/hash/detail/limits.hpp
new file mode 100644
index 0000000..f25b3be
--- /dev/null
+++ b/include/ndnboost/functional/hash/detail/limits.hpp
@@ -0,0 +1,61 @@
+
+// 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)
+//
+// On some platforms std::limits gives incorrect values for long double.
+// This tries to work around them.
+
+#if !defined(NDNBOOST_FUNCTIONAL_HASH_DETAIL_LIMITS_HEADER)
+#define NDNBOOST_FUNCTIONAL_HASH_DETAIL_LIMITS_HEADER
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <ndnboost/limits.hpp>
+
+// On OpenBSD, numeric_limits is not reliable for long doubles, but
+// the macros defined in <float.h> are and support long double when STLport
+// doesn't.
+
+#if defined(__OpenBSD__) || defined(_STLP_NO_LONG_DOUBLE)
+#include <float.h>
+#endif
+
+namespace ndnboost
+{
+ namespace hash_detail
+ {
+ template <class T>
+ struct limits : std::numeric_limits<T> {};
+
+#if defined(__OpenBSD__) || defined(_STLP_NO_LONG_DOUBLE)
+ 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;
+ }
+
+ NDNBOOST_STATIC_CONSTANT(int, digits = LDBL_MANT_DIG);
+ NDNBOOST_STATIC_CONSTANT(int, max_exponent = LDBL_MAX_EXP);
+ NDNBOOST_STATIC_CONSTANT(int, min_exponent = LDBL_MIN_EXP);
+#if defined(_STLP_NO_LONG_DOUBLE)
+ NDNBOOST_STATIC_CONSTANT(int, radix = FLT_RADIX);
+#endif
+ };
+#endif // __OpenBSD__
+ }
+}
+
+#endif
diff --git a/include/ndnboost/functional/hash/extensions.hpp b/include/ndnboost/functional/hash/extensions.hpp
new file mode 100644
index 0000000..b079137
--- /dev/null
+++ b/include/ndnboost/functional/hash/extensions.hpp
@@ -0,0 +1,379 @@
+
+// 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)
+
+// Based on Peter Dimov's proposal
+// http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf
+// issue 6.18.
+
+// This implements the extensions to the standard.
+// It's undocumented, so you shouldn't use it....
+
+#if !defined(NDNBOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP)
+#define NDNBOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP
+
+#include <ndnboost/functional/hash/hash.hpp>
+#include <ndnboost/detail/container_fwd.hpp>
+#include <ndnboost/utility/enable_if.hpp>
+#include <ndnboost/static_assert.hpp>
+#include <ndnboost/preprocessor/repetition/repeat_from_to.hpp>
+#include <ndnboost/preprocessor/repetition/enum_params.hpp>
+
+#if !defined(NDNBOOST_NO_CXX11_HDR_ARRAY)
+# include <array>
+#endif
+
+#if !defined(NDNBOOST_NO_CXX11_HDR_TUPLE)
+# include <tuple>
+#endif
+
+#if !defined(NDNBOOST_NO_CXX11_HDR_MEMORY)
+# include <memory>
+#endif
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#if defined(NDNBOOST_NO_FUNCTION_TEMPLATE_ORDERING)
+#include <ndnboost/type_traits/is_array.hpp>
+#endif
+
+#if NDNBOOST_WORKAROUND(NDNBOOST_MSVC, < 1300)
+#include <ndnboost/type_traits/is_const.hpp>
+#endif
+
+namespace ndnboost
+{
+ template <class A, class B>
+ std::size_t hash_value(std::pair<A, B> const&);
+ template <class T, class A>
+ std::size_t hash_value(std::vector<T, A> const&);
+ template <class T, class A>
+ std::size_t hash_value(std::list<T, A> const& v);
+ template <class T, class A>
+ std::size_t hash_value(std::deque<T, A> const& v);
+ template <class K, class C, class A>
+ std::size_t hash_value(std::set<K, C, A> const& v);
+ template <class K, class C, class A>
+ std::size_t hash_value(std::multiset<K, C, A> const& v);
+ template <class K, class T, class C, class A>
+ std::size_t hash_value(std::map<K, T, C, A> const& v);
+ template <class K, class T, class C, class A>
+ std::size_t hash_value(std::multimap<K, T, C, A> const& v);
+
+ template <class T>
+ std::size_t hash_value(std::complex<T> const&);
+
+ template <class A, class B>
+ std::size_t hash_value(std::pair<A, B> const& v)
+ {
+ std::size_t seed = 0;
+ ndnboost::hash_combine(seed, v.first);
+ ndnboost::hash_combine(seed, v.second);
+ return seed;
+ }
+
+ template <class T, class A>
+ std::size_t hash_value(std::vector<T, A> const& v)
+ {
+ return ndnboost::hash_range(v.begin(), v.end());
+ }
+
+ template <class T, class A>
+ std::size_t hash_value(std::list<T, A> const& v)
+ {
+ return ndnboost::hash_range(v.begin(), v.end());
+ }
+
+ template <class T, class A>
+ std::size_t hash_value(std::deque<T, A> const& v)
+ {
+ return ndnboost::hash_range(v.begin(), v.end());
+ }
+
+ template <class K, class C, class A>
+ std::size_t hash_value(std::set<K, C, A> const& v)
+ {
+ return ndnboost::hash_range(v.begin(), v.end());
+ }
+
+ template <class K, class C, class A>
+ std::size_t hash_value(std::multiset<K, C, A> const& v)
+ {
+ return ndnboost::hash_range(v.begin(), v.end());
+ }
+
+ template <class K, class T, class C, class A>
+ std::size_t hash_value(std::map<K, T, C, A> const& v)
+ {
+ return ndnboost::hash_range(v.begin(), v.end());
+ }
+
+ template <class K, class T, class C, class A>
+ std::size_t hash_value(std::multimap<K, T, C, A> const& v)
+ {
+ return ndnboost::hash_range(v.begin(), v.end());
+ }
+
+ template <class T>
+ std::size_t hash_value(std::complex<T> const& v)
+ {
+ ndnboost::hash<T> hasher;
+ std::size_t seed = hasher(v.imag());
+ seed ^= hasher(v.real()) + (seed<<6) + (seed>>2);
+ return seed;
+ }
+
+#if !defined(NDNBOOST_NO_CXX11_HDR_ARRAY)
+ template <class T, std::size_t N>
+ std::size_t hash_value(std::array<T, N> const& v)
+ {
+ return ndnboost::hash_range(v.begin(), v.end());
+ }
+#endif
+
+#if !defined(NDNBOOST_NO_CXX11_HDR_TUPLE)
+ namespace hash_detail {
+ template <std::size_t I, typename T>
+ inline typename ndnboost::enable_if_c<(I == std::tuple_size<T>::value),
+ void>::type
+ hash_combine_tuple(std::size_t&, T const&)
+ {
+ }
+
+ template <std::size_t I, typename T>
+ inline typename ndnboost::enable_if_c<(I < std::tuple_size<T>::value),
+ void>::type
+ hash_combine_tuple(std::size_t& seed, T const& v)
+ {
+ ndnboost::hash_combine(seed, std::get<I>(v));
+ ndnboost::hash_detail::hash_combine_tuple<I + 1>(seed, v);
+ }
+
+ template <typename T>
+ inline std::size_t hash_tuple(T const& v)
+ {
+ std::size_t seed = 0;
+ ndnboost::hash_detail::hash_combine_tuple<0>(seed, v);
+ return seed;
+ }
+ }
+
+#if !defined(NDNBOOST_NO_CXX11_VARIADIC_TEMPLATES)
+ template <typename... T>
+ inline std::size_t hash_value(std::tuple<T...> const& v)
+ {
+ return ndnboost::hash_detail::hash_tuple(v);
+ }
+#else
+
+ inline std::size_t hash_value(std::tuple<> const& v)
+ {
+ return ndnboost::hash_detail::hash_tuple(v);
+ }
+
+# define NDNBOOST_HASH_TUPLE_F(z, n, _) \
+ template< \
+ NDNBOOST_PP_ENUM_PARAMS_Z(z, n, typename A) \
+ > \
+ inline std::size_t hash_value(std::tuple< \
+ NDNBOOST_PP_ENUM_PARAMS_Z(z, n, A) \
+ > const& v) \
+ { \
+ return ndnboost::hash_detail::hash_tuple(v); \
+ }
+
+ NDNBOOST_PP_REPEAT_FROM_TO(1, 11, NDNBOOST_HASH_TUPLE_F, _)
+# undef NDNBOOST_HASH_TUPLE_F
+#endif
+
+#endif
+
+#if !defined(NDNBOOST_NO_CXX11_SMART_PTR)
+ template <typename T>
+ inline std::size_t hash_value(std::shared_ptr<T> const& x) {
+ return ndnboost::hash_value(x.get());
+ }
+
+ template <typename T, typename Deleter>
+ inline std::size_t hash_value(std::unique_ptr<T, Deleter> const& x) {
+ return ndnboost::hash_value(x.get());
+ }
+#endif
+
+ //
+ // call_hash_impl
+ //
+
+ // On compilers without function template ordering, this deals with arrays.
+
+#if defined(NDNBOOST_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 ndnboost;
+ return hash_value(v);
+ }
+ };
+ };
+
+ template <>
+ struct call_hash_impl<true>
+ {
+ template <class Array>
+ struct inner
+ {
+#if !NDNBOOST_WORKAROUND(NDNBOOST_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 ndnboost::hash_range(v, v + size);
+ }
+ };
+ };
+
+ template <class T>
+ struct call_hash
+ : public call_hash_impl<ndnboost::is_array<T>::value>
+ ::NDNBOOST_NESTED_TEMPLATE inner<T>
+ {
+ };
+ }
+#endif // NDNBOOST_NO_FUNCTION_TEMPLATE_ORDERING
+
+ //
+ // ndnboost::hash
+ //
+
+
+#if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
+
+ template <class T> struct hash
+ : std::unary_function<T, std::size_t>
+ {
+#if !defined(NDNBOOST_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 NDNBOOST_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 ndnboost::hash_range(val, val+n);
+ }
+ };
+#endif
+
+#else // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
+
+ // On compilers without partial specialization, ndnboost::hash<T>
+ // has already been declared to deal with pointers, so just
+ // need to supply the non-pointer version of hash_impl.
+
+ namespace hash_detail
+ {
+ template <bool IsPointer>
+ struct hash_impl;
+
+#if !NDNBOOST_WORKAROUND(NDNBOOST_MSVC, < 1300)
+
+ template <>
+ struct hash_impl<false>
+ {
+ template <class T>
+ struct inner
+ : std::unary_function<T, std::size_t>
+ {
+#if !defined(NDNBOOST_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
+
+ // 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<ndnboost::is_const<T>::value>
+ ::NDNBOOST_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 // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
+}
+
+#endif
diff --git a/include/ndnboost/functional/hash/hash.hpp b/include/ndnboost/functional/hash/hash.hpp
new file mode 100644
index 0000000..7428567
--- /dev/null
+++ b/include/ndnboost/functional/hash/hash.hpp
@@ -0,0 +1,530 @@
+
+// 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)
+
+// Based on Peter Dimov's proposal
+// http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf
+// issue 6.18.
+
+#if !defined(NDNBOOST_FUNCTIONAL_HASH_HASH_HPP)
+#define NDNBOOST_FUNCTIONAL_HASH_HASH_HPP
+
+#include <ndnboost/functional/hash/hash_fwd.hpp>
+#include <functional>
+#include <ndnboost/functional/hash/detail/hash_float.hpp>
+#include <string>
+#include <ndnboost/limits.hpp>
+#include <ndnboost/type_traits/is_enum.hpp>
+#include <ndnboost/type_traits/is_integral.hpp>
+#include <ndnboost/utility/enable_if.hpp>
+
+#if defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
+#include <ndnboost/type_traits/is_pointer.hpp>
+#endif
+
+#if !defined(NDNBOOST_NO_CXX11_HDR_TYPEINDEX)
+#include <typeindex>
+#endif
+
+#if NDNBOOST_WORKAROUND(__GNUC__, < 3) \
+ && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
+#define NDNBOOST_HASH_CHAR_TRAITS string_char_traits
+#else
+#define NDNBOOST_HASH_CHAR_TRAITS char_traits
+#endif
+
+namespace ndnboost
+{
+ namespace hash_detail
+ {
+ 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 float_numbers {};
+
+ template <> struct basic_numbers<bool> :
+ ndnboost::hash_detail::enable_hash_value {};
+ template <> struct basic_numbers<char> :
+ ndnboost::hash_detail::enable_hash_value {};
+ template <> struct basic_numbers<unsigned char> :
+ ndnboost::hash_detail::enable_hash_value {};
+ template <> struct basic_numbers<signed char> :
+ ndnboost::hash_detail::enable_hash_value {};
+ template <> struct basic_numbers<short> :
+ ndnboost::hash_detail::enable_hash_value {};
+ template <> struct basic_numbers<unsigned short> :
+ ndnboost::hash_detail::enable_hash_value {};
+ template <> struct basic_numbers<int> :
+ ndnboost::hash_detail::enable_hash_value {};
+ template <> struct basic_numbers<unsigned int> :
+ ndnboost::hash_detail::enable_hash_value {};
+ template <> struct basic_numbers<long> :
+ ndnboost::hash_detail::enable_hash_value {};
+ template <> struct basic_numbers<unsigned long> :
+ ndnboost::hash_detail::enable_hash_value {};
+
+#if !defined(NDNBOOST_NO_INTRINSIC_WCHAR_T)
+ template <> struct basic_numbers<wchar_t> :
+ ndnboost::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(NDNBOOST_NO_LONG_LONG)
+ template <> struct long_numbers<ndnboost::long_long_type> :
+ ndnboost::hash_detail::enable_hash_value {};
+ template <> struct ulong_numbers<ndnboost::ulong_long_type> :
+ ndnboost::hash_detail::enable_hash_value {};
+#endif
+
+#if defined(NDNBOOST_HAS_INT128)
+ template <> struct long_numbers2<ndnboost::int128_type> :
+ ndnboost::hash_detail::enable_hash_value {};
+ template <> struct ulong_numbers2<ndnboost::uint128_type> :
+ ndnboost::hash_detail::enable_hash_value {};
+#endif
+
+ template <> struct float_numbers<float> :
+ ndnboost::hash_detail::enable_hash_value {};
+ template <> struct float_numbers<double> :
+ ndnboost::hash_detail::enable_hash_value {};
+ template <> struct float_numbers<long double> :
+ ndnboost::hash_detail::enable_hash_value {};
+ }
+
+ template <typename T>
+ typename ndnboost::hash_detail::basic_numbers<T>::type hash_value(T);
+ template <typename T>
+ typename ndnboost::hash_detail::long_numbers<T>::type hash_value(T);
+ template <typename T>
+ typename ndnboost::hash_detail::ulong_numbers<T>::type hash_value(T);
+
+ template <typename T>
+ typename ndnboost::enable_if<ndnboost::is_enum<T>, std::size_t>::type
+ hash_value(T);
+
+#if !NDNBOOST_WORKAROUND(__DMC__, <= 0x848)
+ template <class T> std::size_t hash_value(T* const&);
+#else
+ template <class T> std::size_t hash_value(T*);
+#endif
+
+#if !defined(NDNBOOST_NO_FUNCTION_TEMPLATE_ORDERING)
+ template< class T, unsigned N >
+ std::size_t hash_value(const T (&x)[N]);
+
+ template< class T, unsigned N >
+ std::size_t hash_value(T (&x)[N]);
+#endif
+
+ template <class Ch, class A>
+ std::size_t hash_value(
+ std::basic_string<Ch, std::NDNBOOST_HASH_CHAR_TRAITS<Ch>, A> const&);
+
+ template <typename T>
+ typename ndnboost::hash_detail::float_numbers<T>::type hash_value(T);
+
+#if !defined(NDNBOOST_NO_CXX11_HDR_TYPEINDEX)
+ std::size_t hash_value(std::type_index);
+#endif
+
+ // Implementation
+
+ namespace hash_detail
+ {
+ template <class T>
+ inline std::size_t hash_value_signed(T val)
+ {
+ const int size_t_bits = std::numeric_limits<std::size_t>::digits;
+ // ceiling(std::numeric_limits<T>::digits / size_t_bits) - 1
+ const int length = (std::numeric_limits<T>::digits - 1)
+ / size_t_bits;
+
+ std::size_t seed = 0;
+ T positive = val < 0 ? -1 - val : val;
+
+ // Hopefully, this loop can be unrolled.
+ for(unsigned int i = length * size_t_bits; i > 0; i -= size_t_bits)
+ {
+ seed ^= (std::size_t) (positive >> i) + (seed<<6) + (seed>>2);
+ }
+ seed ^= (std::size_t) val + (seed<<6) + (seed>>2);
+
+ return seed;
+ }
+
+ template <class T>
+ inline std::size_t hash_value_unsigned(T val)
+ {
+ const int size_t_bits = std::numeric_limits<std::size_t>::digits;
+ // ceiling(std::numeric_limits<T>::digits / size_t_bits) - 1
+ const int length = (std::numeric_limits<T>::digits - 1)
+ / size_t_bits;
+
+ std::size_t seed = 0;
+
+ // Hopefully, this loop can be unrolled.
+ for(unsigned int i = length * size_t_bits; i > 0; i -= size_t_bits)
+ {
+ seed ^= (std::size_t) (val >> i) + (seed<<6) + (seed>>2);
+ }
+ seed ^= (std::size_t) val + (seed<<6) + (seed>>2);
+
+ return seed;
+ }
+ }
+
+ template <typename T>
+ typename ndnboost::hash_detail::basic_numbers<T>::type hash_value(T v)
+ {
+ return static_cast<std::size_t>(v);
+ }
+
+ template <typename T>
+ typename ndnboost::hash_detail::long_numbers<T>::type hash_value(T v)
+ {
+ return hash_detail::hash_value_signed(v);
+ }
+
+ template <typename T>
+ typename ndnboost::hash_detail::ulong_numbers<T>::type hash_value(T v)
+ {
+ return hash_detail::hash_value_unsigned(v);
+ }
+
+ template <typename T>
+ typename ndnboost::enable_if<ndnboost::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 !NDNBOOST_WORKAROUND(__DMC__, <= 0x848)
+ template <class T> std::size_t hash_value(T* const& v)
+#else
+ template <class T> std::size_t hash_value(T* v)
+#endif
+ {
+#if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
+ // for some reason ptrdiff_t on OpenVMS compiler with
+ // 64 bit is not 64 bit !!!
+ std::size_t x = static_cast<std::size_t>(
+ reinterpret_cast<long long int>(v));
+#else
+ std::size_t x = static_cast<std::size_t>(
+ reinterpret_cast<std::ptrdiff_t>(v));
+#endif
+ return x + (x >> 3);
+ }
+
+#if defined(NDNBOOST_MSVC)
+#pragma warning(push)
+#if NDNBOOST_MSVC <= 1400
+#pragma warning(disable:4267) // 'argument' : conversion from 'size_t' to
+ // 'unsigned int', possible loss of data
+ // A misguided attempt to detect 64-bit
+ // incompatability.
+#endif
+#endif
+
+#if NDNBOOST_WORKAROUND(NDNBOOST_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
+ {
+ ndnboost::hash<T> hasher;
+ seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
+ }
+
+#if defined(NDNBOOST_MSVC)
+#pragma warning(pop)
+#endif
+
+ template <class It>
+ inline std::size_t hash_range(It first, It last)
+ {
+ std::size_t seed = 0;
+
+ for(; first != last; ++first)
+ {
+ hash_combine(seed, *first);
+ }
+
+ return seed;
+ }
+
+ template <class It>
+ inline void hash_range(std::size_t& seed, It first, It last)
+ {
+ for(; first != last; ++first)
+ {
+ hash_combine(seed, *first);
+ }
+ }
+
+#if NDNBOOST_WORKAROUND(__BORLANDC__, NDNBOOST_TESTED_AT(0x551))
+ template <class T>
+ inline std::size_t hash_range(T* first, T* last)
+ {
+ std::size_t seed = 0;
+
+ for(; first != last; ++first)
+ {
+ ndnboost::hash<T> hasher;
+ seed ^= hasher(*first) + 0x9e3779b9 + (seed<<6) + (seed>>2);
+ }
+
+ return seed;
+ }
+
+ template <class T>
+ inline void hash_range(std::size_t& seed, T* first, T* last)
+ {
+ for(; first != last; ++first)
+ {
+ ndnboost::hash<T> hasher;
+ seed ^= hasher(*first) + 0x9e3779b9 + (seed<<6) + (seed>>2);
+ }
+ }
+#endif
+
+#if !defined(NDNBOOST_NO_FUNCTION_TEMPLATE_ORDERING)
+ template< class T, unsigned N >
+ inline std::size_t hash_value(const T (&x)[N])
+ {
+ return hash_range(x, x + N);
+ }
+
+ template< class T, unsigned N >
+ inline std::size_t hash_value(T (&x)[N])
+ {
+ return hash_range(x, x + N);
+ }
+#endif
+
+ template <class Ch, class A>
+ inline std::size_t hash_value(
+ std::basic_string<Ch, std::NDNBOOST_HASH_CHAR_TRAITS<Ch>, A> const& v)
+ {
+ return hash_range(v.begin(), v.end());
+ }
+
+ template <typename T>
+ typename ndnboost::hash_detail::float_numbers<T>::type hash_value(T v)
+ {
+ return ndnboost::hash_detail::float_hash_value(v);
+ }
+
+#if !defined(NDNBOOST_NO_CXX11_HDR_TYPEINDEX)
+ inline std::size_t hash_value(std::type_index v)
+ {
+ return v.hash_code();
+ }
+#endif
+
+ //
+ // ndnboost::hash
+ //
+
+ // Define the specializations required by the standard. The general purpose
+ // ndnboost::hash is defined later in extensions.hpp if
+ // NDNBOOST_HASH_NO_EXTENSIONS is not defined.
+
+ // NDNBOOST_HASH_SPECIALIZE - define a specialization for a type which is
+ // passed by copy.
+ //
+ // NDNBOOST_HASH_SPECIALIZE_REF - define a specialization for a type which is
+ // passed by copy.
+ //
+ // These are undefined later.
+
+#if !NDNBOOST_WORKAROUND(NDNBOOST_MSVC, < 1300)
+#define NDNBOOST_HASH_SPECIALIZE(type) \
+ template <> struct hash<type> \
+ : public std::unary_function<type, std::size_t> \
+ { \
+ std::size_t operator()(type v) const \
+ { \
+ return ndnboost::hash_value(v); \
+ } \
+ };
+
+#define NDNBOOST_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 ndnboost::hash_value(v); \
+ } \
+ };
+#else
+#define NDNBOOST_HASH_SPECIALIZE(type) \
+ template <> struct hash<type> \
+ : public std::unary_function<type, std::size_t> \
+ { \
+ std::size_t operator()(type v) const \
+ { \
+ return ndnboost::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 ndnboost::hash_value(v); \
+ } \
+ };
+
+#define NDNBOOST_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 ndnboost::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 ndnboost::hash_value(v); \
+ } \
+ };
+#endif
+
+ NDNBOOST_HASH_SPECIALIZE(bool)
+ NDNBOOST_HASH_SPECIALIZE(char)
+ NDNBOOST_HASH_SPECIALIZE(signed char)
+ NDNBOOST_HASH_SPECIALIZE(unsigned char)
+#if !defined(NDNBOOST_NO_INTRINSIC_WCHAR_T)
+ NDNBOOST_HASH_SPECIALIZE(wchar_t)
+#endif
+ NDNBOOST_HASH_SPECIALIZE(short)
+ NDNBOOST_HASH_SPECIALIZE(unsigned short)
+ NDNBOOST_HASH_SPECIALIZE(int)
+ NDNBOOST_HASH_SPECIALIZE(unsigned int)
+ NDNBOOST_HASH_SPECIALIZE(long)
+ NDNBOOST_HASH_SPECIALIZE(unsigned long)
+
+ NDNBOOST_HASH_SPECIALIZE(float)
+ NDNBOOST_HASH_SPECIALIZE(double)
+ NDNBOOST_HASH_SPECIALIZE(long double)
+
+ NDNBOOST_HASH_SPECIALIZE_REF(std::string)
+#if !defined(NDNBOOST_NO_STD_WSTRING)
+ NDNBOOST_HASH_SPECIALIZE_REF(std::wstring)
+#endif
+
+#if !defined(NDNBOOST_NO_LONG_LONG)
+ NDNBOOST_HASH_SPECIALIZE(ndnboost::long_long_type)
+ NDNBOOST_HASH_SPECIALIZE(ndnboost::ulong_long_type)
+#endif
+
+#if defined(NDNBOOST_HAS_INT128)
+ NDNBOOST_HASH_SPECIALIZE(ndnboost::int128_type)
+ NDNBOOST_HASH_SPECIALIZE(ndnboost::uint128_type)
+#endif
+
+#if !defined(NDNBOOST_NO_CXX11_HDR_TYPEINDEX)
+ NDNBOOST_HASH_SPECIALIZE(std::type_index)
+#endif
+
+#undef NDNBOOST_HASH_SPECIALIZE
+#undef NDNBOOST_HASH_SPECIALIZE_REF
+
+// Specializing ndnboost::hash for pointers.
+
+#if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
+
+ template <class T>
+ struct hash<T*>
+ : public std::unary_function<T*, std::size_t>
+ {
+ std::size_t operator()(T* v) const
+ {
+#if !NDNBOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)
+ return ndnboost::hash_value(v);
+#else
+ std::size_t x = static_cast<std::size_t>(
+ reinterpret_cast<std::ptrdiff_t>(v));
+
+ return x + (x >> 3);
+#endif
+ }
+ };
+
+#else
+
+ // For compilers without partial specialization, we define a
+ // ndnboost::hash for all remaining types. But hash_impl is only defined
+ // for pointers in 'extensions.hpp' - so when NDNBOOST_HASH_NO_EXTENSIONS
+ // is defined there will still be a compile error for types not supported
+ // in the standard.
+
+ namespace hash_detail
+ {
+ template <bool IsPointer>
+ struct hash_impl;
+
+ template <>
+ struct hash_impl<true>
+ {
+ template <class T>
+ struct inner
+ : public std::unary_function<T, std::size_t>
+ {
+ std::size_t operator()(T val) const
+ {
+#if !NDNBOOST_WORKAROUND(__SUNPRO_CC, <= 590)
+ return ndnboost::hash_value(val);
+#else
+ std::size_t x = static_cast<std::size_t>(
+ reinterpret_cast<std::ptrdiff_t>(val));
+
+ return x + (x >> 3);
+#endif
+ }
+ };
+ };
+ }
+
+ template <class T> struct hash
+ : public ndnboost::hash_detail::hash_impl<ndnboost::is_pointer<T>::value>
+ ::NDNBOOST_NESTED_TEMPLATE inner<T>
+ {
+ };
+
+#endif
+}
+
+#undef NDNBOOST_HASH_CHAR_TRAITS
+
+#endif // NDNBOOST_FUNCTIONAL_HASH_HASH_HPP
+
+// Include this outside of the include guards in case the file is included
+// twice - once with NDNBOOST_HASH_NO_EXTENSIONS defined, and then with it
+// undefined.
+
+#if !defined(NDNBOOST_HASH_NO_EXTENSIONS) \
+ && !defined(NDNBOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP)
+#include <ndnboost/functional/hash/extensions.hpp>
+#endif