forked from boostorg/container_hash
Add extra overloads for hash_value to cover all the specializations of boost::hash. Fixes 1095
[SVN r38881]
This commit is contained in:
30
doc/ref.xml
30
doc/ref.xml
@@ -479,6 +479,36 @@ for(; first != last; ++first)
|
||||
Implementation of the hash function.
|
||||
</purpose>
|
||||
|
||||
<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>
|
||||
|
@@ -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 @@ namespace boost
|
||||
|
||||
// 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 @@ namespace boost
|
||||
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 @@ namespace boost
|
||||
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
|
||||
//
|
||||
|
@@ -8,6 +8,7 @@ import testing ;
|
||||
project hash-tests
|
||||
: requirements
|
||||
<toolset>gcc:<define>_GLIBCXX_DEBUG
|
||||
"<toolset>gcc:<cxxflags>-Wsign-promo -Wextra"
|
||||
;
|
||||
|
||||
test-suite functional/hash
|
||||
|
Reference in New Issue
Block a user