|
Boost-Commit : |
From: daniel_james_at_[hidden]
Date: 2007-08-23 21:44:16
Author: danieljames
Date: 2007-08-23 21:44:15 EDT (Thu, 23 Aug 2007)
New Revision: 38881
URL: http://svn.boost.org/trac/boost/changeset/38881
Log:
Add extra overloads for hash_value to cover all the specializations of boost::hash. Fixes 1095
Text files modified:
trunk/boost/functional/hash/hash.hpp | 56 +++++++++++++++++++++++++++++++++++-----
trunk/libs/functional/hash/doc/ref.xml | 30 +++++++++++++++++++++
trunk/libs/functional/hash/test/Jamfile.v2 | 1
3 files changed, 80 insertions(+), 7 deletions(-)
Modified: trunk/boost/functional/hash/hash.hpp
==============================================================================
--- trunk/boost/functional/hash/hash.hpp (original)
+++ trunk/boost/functional/hash/hash.hpp 2007-08-23 21:44:15 EDT (Thu, 23 Aug 2007)
@@ -35,17 +35,21 @@
namespace boost
{
-#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
- // Borland complains about an ambiguous function overload
- // when compiling boost::hash<bool>.
std::size_t hash_value(bool);
-#endif
-
+ std::size_t hash_value(char);
+ std::size_t hash_value(unsigned char);
+ std::size_t hash_value(signed char);
+ std::size_t hash_value(short);
+ std::size_t hash_value(unsigned short);
std::size_t hash_value(int);
std::size_t hash_value(unsigned int);
std::size_t hash_value(long);
std::size_t hash_value(unsigned long);
+#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
+ std::size_t hash_value(wchar_t);
+#endif
+
#if defined(BOOST_HAS_LONG_LONG) && defined(_M_X64) && defined(_WIN64)
// On 64-bit windows std::size_t is a typedef for unsigned long long, which
// isn't due to be supported until Boost 1.35. So add support here.
@@ -95,12 +99,34 @@
// Implementation
-#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
inline std::size_t hash_value(bool v)
{
return static_cast<std::size_t>(v);
}
-#endif
+ inline std::size_t hash_value(char v)
+ {
+ return static_cast<std::size_t>(v);
+ }
+
+ inline std::size_t hash_value(unsigned char v)
+ {
+ return static_cast<std::size_t>(v);
+ }
+
+ inline std::size_t hash_value(signed char v)
+ {
+ return static_cast<std::size_t>(v);
+ }
+
+ inline std::size_t hash_value(short v)
+ {
+ return static_cast<std::size_t>(v);
+ }
+
+ inline std::size_t hash_value(unsigned short v)
+ {
+ return static_cast<std::size_t>(v);
+ }
inline std::size_t hash_value(int v)
{
@@ -122,6 +148,13 @@
return static_cast<std::size_t>(v);
}
+#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
+ inline std::size_t hash_value(wchar_t v)
+ {
+ return static_cast<std::size_t>(v);
+ }
+#endif
+
#if defined(BOOST_HAS_LONG_LONG) && defined(_M_X64) && defined(_WIN64)
inline std::size_t hash_value(long long v)
{
@@ -292,6 +325,15 @@
return hash_range(v.begin(), v.end());
}
+ template <class T>
+ std::size_t hash_value(std::complex<T> const& v)
+ {
+ boost::hash<T> hasher;
+ std::size_t seed = hasher(v.imag());
+ seed ^= hasher(v.real()) + (seed<<6) + (seed>>2);
+ return seed;
+ }
+
//
// boost::hash
//
Modified: trunk/libs/functional/hash/doc/ref.xml
==============================================================================
--- trunk/libs/functional/hash/doc/ref.xml (original)
+++ trunk/libs/functional/hash/doc/ref.xml 2007-08-23 21:44:15 EDT (Thu, 23 Aug 2007)
@@ -481,6 +481,36 @@
<signature>
<type>std::size_t</type>
+ <parameter name="val"><paramtype>bool</paramtype></parameter>
+ </signature>
+
+ <signature>
+ <type>std::size_t</type>
+ <parameter name="val"><paramtype>char</paramtype></parameter>
+ </signature>
+
+ <signature>
+ <type>std::size_t</type>
+ <parameter name="val"><paramtype>signed char</paramtype></parameter>
+ </signature>
+
+ <signature>
+ <type>std::size_t</type>
+ <parameter name="val"><paramtype>unsigned char</paramtype></parameter>
+ </signature>
+
+ <signature>
+ <type>std::size_t</type>
+ <parameter name="val"><paramtype>short</paramtype></parameter>
+ </signature>
+
+ <signature>
+ <type>std::size_t</type>
+ <parameter name="val"><paramtype>unsigned short</paramtype></parameter>
+ </signature>
+
+ <signature>
+ <type>std::size_t</type>
<parameter name="val"><paramtype>int</paramtype></parameter>
</signature>
Modified: trunk/libs/functional/hash/test/Jamfile.v2
==============================================================================
--- trunk/libs/functional/hash/test/Jamfile.v2 (original)
+++ trunk/libs/functional/hash/test/Jamfile.v2 2007-08-23 21:44:15 EDT (Thu, 23 Aug 2007)
@@ -8,6 +8,7 @@
project hash-tests
: requirements
<toolset>gcc:<define>_GLIBCXX_DEBUG
+ "<toolset>gcc:<cxxflags>-Wsign-promo -Wextra"
;
test-suite functional/hash
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk