|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r69520 - in trunk: boost/tr1 libs/tr1/test
From: john_at_[hidden]
Date: 2011-03-03 11:55:26
Author: johnmaddock
Date: 2011-03-03 11:55:10 EST (Thu, 03 Mar 2011)
New Revision: 69520
URL: http://svn.boost.org/trac/boost/changeset/69520
Log:
Make std::tr1::hash a thin wrapper around boost::hash so folks can specialise it.
Fixes #5254.
Text files modified:
trunk/boost/tr1/functional.hpp | 7 ++++++-
trunk/libs/tr1/test/test_hash.cpp | 25 ++++++++++++++++++++++++-
2 files changed, 30 insertions(+), 2 deletions(-)
Modified: trunk/boost/tr1/functional.hpp
==============================================================================
--- trunk/boost/tr1/functional.hpp (original)
+++ trunk/boost/tr1/functional.hpp 2011-03-03 11:55:10 EST (Thu, 03 Mar 2011)
@@ -128,7 +128,12 @@
}
namespace std{ namespace tr1{
- using ::boost::hash;
+ //using ::boost::hash;
+
+ template <class T>
+ struct hash : public boost::hash<T>
+ {
+ };
}}
Modified: trunk/libs/tr1/test/test_hash.cpp
==============================================================================
--- trunk/libs/tr1/test/test_hash.cpp (original)
+++ trunk/libs/tr1/test/test_hash.cpp 2011-03-03 11:55:10 EST (Thu, 03 Mar 2011)
@@ -31,7 +31,29 @@
verify_return_type(ch(t), std::size_t(0));
}
-class UDT;
+class UDT
+{
+ int m_value;
+public:
+ UDT(int v) : m_value(v) {}
+ int value()const { return m_value; }
+};
+
+namespace std{ namespace tr1{
+
+template<>
+struct hash<UDT> : public std::unary_function<UDT, std::size_t>
+{
+ typedef UDT argument_type;
+ typedef std::size_t result_type;
+ std::size_t operator()(const UDT& u)const
+ {
+ std::tr1::hash<int> h;
+ return h(u.value());
+ }
+};
+
+}}
int main()
{
@@ -55,6 +77,7 @@
check_hash(static_cast<const UDT*>(0));
check_hash(static_cast<volatile UDT*>(0));
check_hash(static_cast<const volatile UDT*>(0));
+ check_hash(UDT(1));
return 0;
}
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