|
Boost Users : |
Subject: Re: [Boost-users] Unwanted implicit conversions to bool
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2011-05-12 10:17:11
On 12.05.2011 12:58, Dominik Steenken wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hello everyone,
>
> i am having a bit of a problem using boost/hash in combination with
> boost/shared_ptr. Essentially, what i want when i hash a shared_ptr
> object is to hash the object it points to. So i wrote a template
> function to that effect, i.e.
>
> inline std::size_t hash_value(boost::shared_ptr<const IHashable> obj)
> {
> return obj->hash_value();
> }
>
> where IHashable is an interface forcing the existence of the
> hash_value() function. Now i am getting compiler errors because
> apparently there is an implicit conversion to bool from
> boost::shared_ptr<T> and obviously there is a hash function for bool.
> Thus, something like
>
> boost::shared_ptr<IHashable> p(new something());
> boost::hasher<something> hasher;
> std::size_t hash = hasher(p);
>
> is now ambiguous.
Add
inline std::size_t hash_value(boost::shared_ptr<IHashable> obj)
{
return hash_value(static_cast<boost::shared_ptr<const IHashable> >(obj));
}
Sebastian
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net