This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4296. Clarify that Cpp17Hash does not imply stateless

Section: 16.4.4.5 [hash.requirements] Status: New Submitter: Jonathan Wakely Opened: 2025-07-18 Last modified: 2025-07-18

Priority: Not Prioritized

View all other issues in [hash.requirements].

View all issues with New status.

Discussion:

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 18.2 [concepts.equality].

Proposed resolution: