|
Boost Users : |
Subject: Re: [Boost-users] Boost.Hash and enums
From: Daniel James (dnljms_at_[hidden])
Date: 2012-08-22 07:10:16
On 22 August 2012 11:49, Filip KonviÄka <filip.konvicka_at_[hidden]> 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.
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