Boost logo

Boost :

From: John Maddock (jz.maddock_at_[hidden])
Date: 2021-06-05 17:02:35

What's the best way to combine a hash value with a bool?

Specifically, if you're generating a hash value for a class which has a
one member a bool.  Normally I would just boost::hash_combine all the
class members together, but doing that with a bool member leads to:

warning C4805: '^': unsafe mix of type 'T' and type 'size_t' in operation
1>        with
1>        [
1>            T=bool
1>        ]

Followed by a long instantiation backtrace (this is from

Since there's only one bool in this class, I could just apply a unary ~ 
to the value when the bool is true, but obviously that wouldn't work for
classes with multiple bool's.  Should we modify hash_combine for this
use case?

Cheers, John.

This email has been checked for viruses by Avast antivirus software.

Boost list run by bdawes at, gregod at, cpdaniel at, john at