Hi, In Boost 1.51, it looks to me like boost::hash_value no longer knows how to handle enums anymore. Is the following the right way to tell it to treat enums like ints? #if (BOOST_VERSION >= 105100) // Boost 1.51.0+ namespace boost { /// Enable hashing of enums. template<typename E> size_t hash_value( E const e, typename std::enable_if<std::is_enum<E>::value, E>::type def = static_cast<E>(0)) { return hash_value((int)e); } } #endif Is enum hashing support going to be added to the library in the future? Thanks, Filip
On 22 August 2012 11:49, Filip Konvička <filip.konvicka@logis.cz> wrote:
Hi,
In Boost 1.51, it looks to me like boost::hash_value no longer knows how to handle enums anymore.
Sorry, I prevented hashing by implicit casts in this release, I didn't realise it would break enum support.
Is the following the right way to tell it to treat enums like ints?
#if (BOOST_VERSION >= 105100) // Boost 1.51.0+ namespace boost { /// Enable hashing of enums. template<typename E> size_t hash_value( E const e, typename std::enable_if<std::is_enum<E>::value, E>::type def = static_cast<E>(0)) { return hash_value((int)e); } } #endif
I think that should work. I'll see if can get a portable version in trunk as soon as possible.
In Boost 1.51, it looks to me like boost::hash_value no longer knows how to handle enums anymore.
Sorry, I prevented hashing by implicit casts in this release, I didn't realise it would break enum support.
And that's fine, I always prefer to have fewer implicit casts. I just wanted to make sure that my code makes sense.
... I think that should work. I'll see if can get a portable version in trunk as soon as possible.
I only tested my code with MSVC 2010. I hope it works with g++ as well. Thanks, Filip
... I think that should work. I'll see if can get a portable version in trunk as soon as possible.
I only tested my code with MSVC 2010. I hope it works with g++ as well.
Sure enough, it does not. g++ is using argument-dependent lookup; my application code encloses enum definitions in dedicated namespaces and some enums are defined in classes. In all such cases, my code understandably does not work. Do you have any idea how to overcome this? Thanks, Filip
Hi, I got into the same trouble after upgrading to version 1.51. Therefore, I wrote a preprocessor macro which lifts an enum-type into the new SFINAE-guarded hash-world. I hope that helps until the problem is fixed. regards, Tobias -- View this message in context: http://boost.2283326.n4.nabble.com/Boost-Hash-and-enums-tp4634592p4635431.ht... Sent from the Boost - Users mailing list archive at Nabble.com.
On 24 August 2012 16:33, Filip Konvička <filip.konvicka@logis.cz> wrote:
...
I think that should work. I'll see if can get a portable version in trunk as soon as possible.
I only tested my code with MSVC 2010. I hope it works with g++ as well.
Sure enough, it does not. g++ is using argument-dependent lookup; my application code encloses enum definitions in dedicated namespaces and some enums are defined in classes. In all such cases, my code understandably does not work. Do you have any idea how to overcome this?
Sorry, I missed this. You need to declare your hash function before including the header. There's enum support in the release branch now, so it'll be fixed in the next release.
participants (3)
-
Daniel James
-
Filip Konvička
-
Tobias Loew