From 4727f1070a91d52786db7b358e3d846394cedb33 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 10 Apr 2005 12:36:24 +0000 Subject: [PATCH] Implement hash functions for built-in arrays. Uses partial specialization instead of function overloading - which disobeys the specification of the extension (hash_combine is defined in terms of hash_value, but hash_value doesn't deal with every case now). [SVN r28078] --- include/boost/functional/hash/hash.hpp | 74 ++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/include/boost/functional/hash/hash.hpp b/include/boost/functional/hash/hash.hpp index 73bf885..1693110 100644 --- a/include/boost/functional/hash/hash.hpp +++ b/include/boost/functional/hash/hash.hpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace boost { @@ -95,6 +96,7 @@ namespace boost namespace hash_detail { +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) // This allows boost::hash to be specialised for classes in the // standard namespace. It appears that a strict two phase template // implementation only finds overloads that are in the current @@ -110,6 +112,65 @@ namespace boost return hash_value(v); } }; + + template + struct call_hash + { + static std::size_t call(T const* val) + { + return boost::hash_range(val, val + Size); + } + }; + +#if !defined(__BORLANDC__) + template + struct call_hash + { + static std::size_t call(T const*) + { + return 0; + } + }; +#endif +#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + template + struct call_hash_impl + { + template + struct inner + { + static std::size_t call(T const& v) + { + using namespace boost; + return hash_value(v); + } + }; + }; + + template <> + struct call_hash_impl + { + template + struct inner + { + template + static T array_member(T* array); + + static std::size_t call(Array const& v) + { + const int size = sizeof(v) / sizeof(array_member(v)); + return boost::hash_range(v, v + size); + } + }; + }; + + template + struct call_hash + : public call_hash_impl::value> + ::BOOST_NESTED_TEMPLATE inner + { + }; +#endif } template @@ -206,6 +267,19 @@ namespace boost return hash_detail::call_hash::call(val); } }; + +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ + && !defined(__BORLANDC__) + + template struct hash + : std::unary_function + { + std::size_t operator()(T const*) const + { + return 0; + } + }; +#endif } #endif