|
Boost Users : |
Subject: [Boost-users] Unwanted implicit conversions to bool
From: Dominik Steenken (dominik_at_[hidden])
Date: 2011-05-12 06:58:07
-----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. I already found the BOOST_HASH_NO_IMPLICIT_CASTS
switch, but it does not seem to change anything. I still get compiler
errors like this one:
In file included from /usr/include/boost/functional/hash/hash.hpp:
494:0,
from /usr/include/boost/functional/hash.hpp:6,
from types/../common.h:14,
from types/variables.h:11,
from types/abstractformula.h:11,
from types/unaryoperations.h:11,
from types/unaryoperations.cpp:1:
types/unaryoperations.cpp:49:37: instantiated from here
/usr/include/boost/functional/hash/extensions.hpp:176:34: error:
call of overloaded ?hash_value(const
boost::shared_ptr<terms::CAbstractFormula>&)? is ambiguous
/usr/include/boost/functional/hash/hash.hpp:120:24: note: candidates
are: size_t boost::hash_value(bool)
types/../common.h:86:24: note: size_t
terms::hash_value(boost::shared_ptr<const terms::IHashable>)
Any idea on what i could to to prevent this would be greatly
appreciated.
cheers,
Dominik
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQIcBAEBAgAGBQJNy70+AAoJEPKXvh6MABK35dkQAKRFv48yZ7XyZh/6F+SSh02G
IBfSEMi/xMXerLRH+/FV2lB6/gx1tymkYXxF02gopfIlavHHTWPz0vnkqZYFAABq
ZzLMpggx4G50KtUGZfeKKfMGdbR5+0AHHT5ZRuL6aTzsvgr6nMYDdxwBKlAPvTJv
nDuH8fHaV2QU6tw8OSmqzsdtiKrA4rnSqLPg4T6g/e/EqvH2Pf8GkXowRVK0T9Sq
uAPnqcNZcMPuaIbtACC+AzsVA3CBw5fFQktRVbkLUtqDRVr10a9qOxgnDo6b7Duz
c/KGNnWH2n1Lnwp9GbrvZoScqwThr9WqBvdcITD3ivgAkWhy5Fy6pnR1leRZhbZ7
+eFv3c1tY7b4yE7I9qCfRwW8LDhnkAJ/nAdcmGhWNX8RRSkETTguoCe9KUPMPoSs
MBUEVk8VUNC9J3/JQmxlDhVju4WvJjlAnYrf7zir2XTFQ7v5eP86BeXkYArl+eyg
OI2qRVp2ZuhReorwDc09Hef4/NrXPy3Bpq5nEWsref/mBbsyeopH3wqTZBrtruky
RtSiJInhm4CETfMVJ8aJh/QO3MzGw2PXRLLCQ/mR2xHRgvEWOH53r84/1s8H3uSA
URvXvPLKBuTpog30+GhHgfWOYx1/1Hy3atHbR9XikNW9y6Pv8IxUISA4AaQXNZyn
XkjTDMHQ5XAqj/6Etgr7
=ak4K
-----END PGP SIGNATURE-----
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