|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4296" status="New"> |
| 5 | +<title>Clarify that Cpp17Hash does not imply stateless</title> |
| 6 | +<section><sref ref="[hash.requirements]"/></section> |
| 7 | +<submitter>Jonathan Wakely</submitter> |
| 8 | +<date>18 Jul 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +A colleague was mislead into thinking that the <i>Cpp17Hash</i> requirements |
| 14 | +imply hash functions must be stateless, so that every `h` would produce the |
| 15 | +same value for `h(k)`. The normative wording and the note can be interpreted |
| 16 | +as saying that the value of `h` is not relevant, only `k` matters. |
| 17 | +</p> |
| 18 | +<blockquote> |
| 19 | +The value returned shall depend only on the argument `k` for the duration |
| 20 | +of the program. |
| 21 | +<p> |
| 22 | +[<i>Note 1</i>: Thus all evaluations of the expression `h(k)` with the same |
| 23 | +value for `k` yield the same result for a given execution of the program. |
| 24 | +— <i>end note</i>] |
| 25 | +</p> |
| 26 | +</blockquote> |
| 27 | +<p> |
| 28 | +I initially proposed changing it to "with the same values for `h` and `k` |
| 29 | +but Jens observed that if `h(k)` is allowed to change `h` then a subsequent |
| 30 | +call would not meet the condition "the same value of `h`". |
| 31 | +We should also clarify that the evaluation of `h(k)` should not change `h`, |
| 32 | +so that we have the same value of `h` each time. |
| 33 | +</p> |
| 34 | +<p> |
| 35 | +Arguably, the wording in p2 "`h` is a value of type (possibly const) `H`" |
| 36 | +already covers this. It suggests to me that the effects in the table are for |
| 37 | +a particular value `h`, so for <i>that</i> value, the result of calling `h(k)` |
| 38 | +depends only on the value of `k` |
| 39 | +(and not on the current time, ambient temperature in Denmark, |
| 40 | +or the output of a random number generator). And the fact that `h` can be |
| 41 | +a value of type `const H` implies that calling `h(k)` doesn't change `h`. |
| 42 | +</p> |
| 43 | +<p> |
| 44 | +Maybe we want to clarify it in terms of equality-preserving |
| 45 | +<sref ref="[concepts.equality]"/>. |
| 46 | +</p> |
| 47 | +</discussion> |
| 48 | + |
| 49 | +<resolution> |
| 50 | +<p> |
| 51 | +</p> |
| 52 | +</resolution> |
| 53 | + |
| 54 | +</issue> |
0 commit comments