Subject: Re: [boost] [functional] [shared_ptr] boost::hash<shared_ptr<T>> Returns Only Two Values
From: Daniel James (dnljms_at_[hidden])
Date: 2011-02-18 14:58:01
On 18 February 2011 19:40, Stewart, Robert <Robert.Stewart_at_[hidden]> wrote:
> The following is a program that demonstrates that a null shared_ptr<int> produces a hash value of zero and that (ostensibly) all non-null instances produce a hash value of one.
This is known, it happens because shared_ptr can be implicitly cast to
bool, so it uses that. If you set BOOST_HASH_NO_IMPLICIT_CASTS it
won't happen. This macro isn't set by default because I'm not sure if
there will be any other consequences from preventing implicit casts,
but it might be in a future version.
> I expected that there'd be a shared_ptr specialization of hash_value to make it work right, but I don't find one. Shouldn't there be one?
That's an issue for the shared_ptr implementation.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk