boost::hash_value not picking up std::hash specialisations

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

boost::hash_value not picking up std::hash specialisations

Boost - Users mailing list
Hi,

I'm trying to move away from Qt containers in my source code, and Qt
5.15 makes that a bit easier by providing specialisations for some its
types.

Now I have a struct S { QLatin1String a, b; } that I'd like to hash.

I can use boost::hash_combine to implement std::hash<S>, but S is
actually a nested type, and with qHash(), I could just write an overload
as a hidden friend, and I figured I could do the same with hash_value()
(at the cost of having to specify boost::hash<S> as a unordered_map
template argument).

But hash_combine seems to insist on hash_value which in turn doesn't
look at std::hash at all:

       size_t seed = 0;
       boost::hash_combine(seed, key.a); // ERROR: no hash_value overload
for QLatin1String
       boost::hash_combine(seed, key.b); // Ditto
       return seed;

expected: calls std::hash<QLatin1String>{}::op() (if it exists).

It's trivial to write hash_value(QLatin1String), of course, but what's
the general strategy here? Shouldn't hash_combine() look for
std::hash<T> first? And, speaking as a Qt developer: do I really need to
provide qHash(), std::hash<T> _and_ hash_value(T) for every hashable T?!

Thanks,
Marc
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: boost::hash_value not picking up std::hash specialisations

Boost - Users mailing list
On 2020-12-21 11:55, Marc Mutz via Boost-users wrote:
> I'm trying to move away from Qt containers in my source code, and Qt
> 5.15 makes that a bit easier by providing

+ std::hash

> specialisations for some its types.
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users