Boost logo

Boost :

From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2021-10-17 09:25:27


On 10/17/21 1:44 AM, Peter Dimov via Boost wrote:
> At the moment, boost::hash_value for complex<T> is specified as
>
> When T is a built in type and val.imag() == 0, the result is equal
> to hash_value(val.real()). Otherwise an unspecified value, except
> that equal arguments shall yield the same result.
>
> This is a bit odd; the natural implementation for a two-argument
> point/tuple type is
>
> std::size_t seed = 0;
>
> boost::hash_combine( seed, v.real() );
> boost::hash_combine( seed, v.imag() );
>
> return seed;
>
> Can anyone offer an opinion on whether or why the original behavior
> is preferable?

Not that I have a particular opinion on one way or another, but having
the hash changing the value between releases could be a breaking change,
if someone is using it e.g. in a memory mapped file. If the hash values
change as a result of your work, please be sure to mention it in the
release notes.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk