<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4296: Clarify that Cpp17Hash does not imply stateless</title>
<meta property="og:title" content="Issue 4296: Clarify that Cpp17Hash does not imply stateless">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4296.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#New">New</a> status.</em></p>
<h3 id="4296"><a href="lwg-active.html#4296">4296</a>. Clarify that Cpp17Hash does not imply stateless</h3>
<p><b>Section:</b> 16.4.4.5 <a href="https://wg21.link/hash.requirements">[hash.requirements]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2025-07-18 <b>Last modified:</b> 2025-07-18</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#hash.requirements">issues</a> in [hash.requirements].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
A colleague was mislead into thinking that the <i>Cpp17Hash</i> requirements
imply hash functions must be stateless, so that every <code class='backtick'>h</code> would produce the
same value for <code class='backtick'>h(k)</code>. The normative wording and the note can be interpreted
as saying that the value of <code class='backtick'>h</code> is not relevant, only <code class='backtick'>k</code> matters.
</p>
<blockquote>
The value returned shall depend only on the argument <code class='backtick'>k</code> for the duration
of the program.
<p>
[<i>Note 1</i>: Thus all evaluations of the expression <code class='backtick'>h(k)</code> with the same
value for <code class='backtick'>k</code> yield the same result for a given execution of the program.
&mdash; <i>end note</i>]
</p>
</blockquote>
<p>
I initially proposed changing it to "with the same values for <code class='backtick'>h</code> and <code class='backtick'>k</code>
but Jens observed that if <code class='backtick'>h(k)</code> is allowed to change <code class='backtick'>h</code> then a subsequent
call would not meet the condition "the same value of <code class='backtick'>h</code>".
We should also clarify that the evaluation of <code class='backtick'>h(k)</code> should not change <code class='backtick'>h</code>,
so that we have the same value of <code class='backtick'>h</code> each time.
</p>
<p>
Arguably, the wording in p2 "<code class='backtick'>h</code> is a value of type (possibly const) <code class='backtick'>H</code>"
already covers this. It suggests to me that the effects in the table are for
a particular value <code class='backtick'>h</code>, so for <i>that</i> value, the result of calling <code class='backtick'>h(k)</code>
depends only on the value of <code class='backtick'>k</code>
(and not on the current time, ambient temperature in Denmark,
or the output of a random number generator). And the fact that <code class='backtick'>h</code> can be
a value of type <code class='backtick'>const H</code> implies that calling <code class='backtick'>h(k)</code> doesn't change <code class='backtick'>h</code>.
</p>
<p>
Maybe we want to clarify it in terms of equality-preserving
18.2 <a href="https://wg21.link/concepts.equality">[concepts.equality]</a>.
</p>


<p id="res-4296"><b>Proposed resolution:</b></p>
<p>
</p>





</body>
</html>
