I am using boost for tr1 instead of gcc 4.5's native tr1 libraries (by prioritizing boost tr1 headers over gcc headers). There is a compile problem specializing std::tr1::hash.
#include <functional>
#include <memory>
template <class A>
struct std::tr1::hash< std::tr1::shared_ptr<A> >
: public unary_function< std::tr1::shared_ptr<A>, size_t>
{
typedef std::tr1::shared_ptr<A> _Kty;
size_t operator()(const _Kty& p) const
{
return std::tr1::hash<A*>()(p.get());
}
};
The gcc error is:
error: specialization of 'template<class T> struct boost::hash' in different namespace
What will be the correct method to specialize the hash functor in tr1 namespace? Currently I am using a preprocessor directive to switch between specializing hash functor and overloading:
template<class A>
size_t hash_value(const shared_ptr<A> &ptr);
But I will prefer to specialize hash functor as hash_value is not standard.