Created on 2025-07-18.00:00:00 last changed 1 month ago
A colleague was mislead into thinking that the Cpp17Hash requirements imply hash functions must be stateless, so that every `h` would produce the same value for `h(k)`. The normative wording and the note can be interpreted as saying that the value of `h` is not relevant, only `k` matters.
The value returned shall depend only on the argument `k` for the duration of the program.[Note 1: Thus all evaluations of the expression `h(k)` with the same value for `k` yield the same result for a given execution of the program. — end note]
I initially proposed changing it to "with the same values for `h` and `k` but Jens observed that if `h(k)` is allowed to change `h` then a subsequent call would not meet the condition "the same value of `h`". We should also clarify that the evaluation of `h(k)` should not change `h`, so that we have the same value of `h` each time.
Arguably, the wording in p2 "`h` is a value of type (possibly const) `H`" already covers this. It suggests to me that the effects in the table are for a particular value `h`, so for that value, the result of calling `h(k)` depends only on the value of `k` (and not on the current time, ambient temperature in Denmark, or the output of a random number generator). And the fact that `h` can be a value of type `const H` implies that calling `h(k)` doesn't change `h`.
Maybe we want to clarify it in terms of equality-preserving [concepts.equality].
History | |||
---|---|---|---|
Date | User | Action | Args |
2025-07-18 00:00:00 | admin | create |