Hereafter, we use N4140 (C++14 Standard).
According to § 17.6.3.4 Hash requirements,
The value returned shall depend only on t
There is no need for the hash function to be deterministic between runs, but you can still provide your own hash, e.g. for unordered containers if it's a behavior you rely on.
As for why, cppreference says:
Hash functions are only required to produce the same result for the same input within a single execution of a program; this allows salted hashes that prevent collision denial-of-service attacks.
If the Hash
requirements tells it to be deterministic, then you wouldn't be able to provide a salted hash without breaking the requirement.
Here is the actual explanation why