<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2109: Incorrect requirements for hash specializations</title>
<meta property="og:title" content="Issue 2109: Incorrect requirements for hash specializations">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2109.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#C++14">C++14</a> status.</em></p>
<h3 id="2109"><a href="lwg-defects.html#2109">2109</a>. Incorrect requirements for <code>hash</code> specializations</h3>
<p><b>Section:</b> 19.5.7 <a href="https://wg21.link/syserr.hash">[syserr.hash]</a>, 20.3.3 <a href="https://wg21.link/util.smartptr.hash">[util.smartptr.hash]</a>, 22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>, 17.7.6 <a href="https://wg21.link/type.index.synopsis">[type.index.synopsis]</a>, 27.4.6 <a href="https://wg21.link/basic.string.hash">[basic.string.hash]</a>, 23.3.14 <a href="https://wg21.link/vector.bool">[vector.bool]</a>, 32.4.3.2 <a href="https://wg21.link/thread.thread.id">[thread.thread.id]</a> <b>Status:</b> <a href="lwg-active.html#C++14">C++14</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2011-12-04 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++14">C++14</a> status.</p>
<p><b>Discussion:</b></p>

<p>
20.3.3 <a href="https://wg21.link/util.smartptr.hash">[util.smartptr.hash]</a> p2 is specified as follows:
</p>

<blockquote><p>
<i>Requires</i>: the template specializations shall meet the requirements of class template 
<code>hash</code> (20.8.12).
</p></blockquote>

<p>
The problem here is the usage of a <i>Requires</i> element, which is actually a pre-condition
that a <em>user</em> of a component has to satisfy. But the intent of this wording is actually
to be a requirement on implementations. The <i>Requires</i> element should be removed here and
the wording should be improved to say what it was intended for.
<p/>
We have similar situations in basically all other places where the specification of library-provided
<code>hash</code> specializations is defined. Usually, the <i>Requires</i> element is incorrect. In the
special case of <code>hash&lt;unique_ptr&lt;T, D&gt;&gt;</code> the implementation depends on 
the behaviour of <code>hash</code> specializations, that could be user-provided. In this case
the specification needs to separate the requirements on these specializations and those
that are imposed on the implementation.
</p>


<p><i>[2012, Kona]</i></p>

<p>
Update wording and move to Review.
</p>
<p>
Believe a simpler formulation is to simply string the term <i>Requires:</i> and leave the
current wording intact, rather than strike the whole clause and replace it.
</p>

<p><i>[Originally proposed wording for reference
<ol>
<li><p>Change 19.5.7 <a href="https://wg21.link/syserr.hash">[syserr.hash]</a> as indicated:</p>

<blockquote><pre>
template &lt;&gt; struct hash&lt;error_code&gt;;
</pre><blockquote>
<p>
-1- <del><i>Requires</i>: the template specialization shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>)</del><ins>The header 
<code>&lt;system_error&gt;</code> provides a definition for a specialization of the 
template <code>hash&lt;error_code&gt;</code>. The requirements for the members of 
this specialization are given in sub-clause 22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a></ins>.
</p>
</blockquote></blockquote>
</li>

<li><p>Change 22.9.3 <a href="https://wg21.link/bitset.hash">[bitset.hash]</a> as indicated:</p>

<blockquote><pre>
template &lt;size_t N&gt; struct hash&lt;bitset&lt;N&gt; &gt;;
</pre><blockquote>
<p>
-1- <del><i>Requires</i>: the template specialization shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>)</del><ins>The header 
<code>&lt;bitset&gt;</code> provides a definition for a partial specialization of the 
<code>hash</code> class template for specializations of class template <code>bitset&lt;N&gt;</code>. 
The requirements for the members of instantiations of this specialization are given 
in sub-clause 22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a></ins>.
</p>
</blockquote></blockquote>
</li>

<li><p>Change 20.3.3 <a href="https://wg21.link/util.smartptr.hash">[util.smartptr.hash]</a> as indicated:</p>

<blockquote><pre>
template &lt;class T, class D&gt; struct hash&lt;unique_ptr&lt;T, D&gt; &gt;;
</pre><blockquote>
<p>
-1- <del><i>Requires</i>: the template specialization shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>)</del><ins>The header 
<code>&lt;memory&gt;</code> provides a definition for a partial specialization of the 
<code>hash</code> class template for specializations of class template <code>unique_ptr&lt;T, D&gt;</code>. 
The requirements for the members of instantiations of this specialization are given 
in sub-clause 22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a></ins>. For an object <code>p</code> of type 
<code>UP</code>, where <code>UP</code> is <code>unique_ptr&lt;T, D&gt;</code>, 
<code>hash&lt;UP&gt;()(p)</code> shall evaluate to the same value as 
<code>hash&lt;typename UP::pointer&gt;()(p.get())</code>. <del>The specialization 
<code>hash&lt;typename UP::pointer&gt;</code> shall be well-formed.</del>
<p/>
<ins>-?- <i>Requires</i>: The specialization <code>hash&lt;typename UP::pointer&gt;</code> 
shall be well-formed and well-defined [<i>Note:</i> the general requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>) are implied &mdash; 
<i>end note</i>].</ins>
</p>
</blockquote></blockquote>

<blockquote><pre>
template &lt;class T&gt; struct hash&lt;shared_ptr&lt;T&gt; &gt;;
</pre><blockquote>
<p>
-2- <del><i>Requires</i>: the template specialization shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>)</del><ins>The header 
<code>&lt;memory&gt;</code> provides a definition for a partial specialization of the 
<code>hash</code> class template for specializations of class template <code>shared_ptr&lt;T&gt;</code>. 
The requirements for the members of instantiations of this specialization are given 
in sub-clause 22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a></ins>. For an object <code>p</code> of type 
<code>shared_ptr&lt;T&gt;</code>, <code>hash&lt;shared_ptr&lt;T&gt; &gt;()(p)</code> 
shall evaluate to the same value as <code>hash&lt;T*&gt;()(p.get())</code>.
</p>
</blockquote></blockquote>
</li>

<li><p>Change 22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a> p2 as indicated: [<i>Comment</i>: For unknown
reasons the extended integer types are not mentioned here, which looks like an oversight to
me and makes also the wording more complicated. See <a href="lwg-defects.html#2119" title="Missing hash specializations for extended integer types (Status: C++17)">2119</a><sup><a href="https://cplusplus.github.io/LWG/issue2119" title="Latest snapshot">(i)</a></sup> for this part
of the problem. &mdash; <i>end comment</i>]</p>

<blockquote><pre>
template &lt;&gt; struct hash&lt;bool&gt;;
template &lt;&gt; struct hash&lt;char&gt;;
[&hellip;]
template &lt;&gt; struct hash&lt;long double&gt;;
template &lt;class T&gt; struct hash&lt;T*&gt;;
</pre><blockquote>
<p>
-2- <del><i>Requires</i>: the template specializations shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>)</del><ins>The header 
<code>&lt;functional&gt;</code> provides definitions for specializations of the 
<code>hash</code> class template for each <i>cv</i>-unqualified arithmetic type except 
for the extended integer types. This header also provides a definition for a partial 
specialization of the <code>hash</code> class template for any pointer type. The 
requirements for the members of these specializations are given in sub-clause 
22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a></ins>.
</p>
</blockquote></blockquote>
</li>

<li><p>Change  [type.index.hash] p1 as indicated:</p>

<blockquote><pre>
template &lt;&gt; struct hash&lt;type_index&gt;;
</pre><blockquote>
<p>
-1- <del><i>Requires</i>: the template specialization shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>)</del><ins>The header 
<code>&lt;typeindex&gt;</code> provides a definition for a specialization of the 
template <code>hash&lt;type_index&gt;</code>. The requirements for the members 
of this specialization are given in sub-clause 22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a></ins>. For 
an object <code>index</code> of type <code>type_index</code>, <code>hash&lt;type_index&gt;()(index)</code> 
shall evaluate to the same result as <code>index.hash_code()</code>.
</p>
</blockquote></blockquote>
</li>

<li><p>Change 27.4.6 <a href="https://wg21.link/basic.string.hash">[basic.string.hash]</a> p1 as indicated:</p>

<blockquote><pre>
template &lt;&gt; struct hash&lt;string&gt;;
template &lt;&gt; struct hash&lt;u16string&gt;;
template &lt;&gt; struct hash&lt;u32string&gt;;
template &lt;&gt; struct hash&lt;wstring&gt;;
</pre><blockquote>
<p>
-1- <del><i>Requires</i>: the template specializations shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>)</del><ins>The header 
<code>&lt;string&gt;</code> provides definitions for specializations of the 
<code>hash</code> class template for the types <code>string</code>, <code>u16string</code>,
<code>u32string</code>, and <code>wstring</code>. The requirements for the members 
of these specializations are given in sub-clause 22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a></ins>.
</p>
</blockquote></blockquote>
</li>

<li><p>Change 23.3.14 <a href="https://wg21.link/vector.bool">[vector.bool]</a> p7 as indicated:</p>

<blockquote><pre>
template &lt;class Allocator&gt; struct hash&lt;vector&lt;bool, Allocator&gt; &gt;;
</pre><blockquote>
<p>
-7- <del><i>Requires</i>: the template specialization shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>)</del><ins>The header 
<code>&lt;vector&gt;</code> provides a definition for a partial specialization of the 
<code>hash</code> class template for specializations of class template <code>vector&lt;bool, Allocator&gt;</code>. 
The requirements for the members of instantiations of this specialization are given 
in sub-clause 22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a></ins>.
</p>
</blockquote></blockquote>
</li>

<li><p>Change 32.4.3.2 <a href="https://wg21.link/thread.thread.id">[thread.thread.id]</a> p14 as indicated:</p>

<blockquote><pre>
template &lt;&gt; struct hash&lt;thread::id&gt;;
</pre><blockquote>
<p>
-14- <del><i>Requires</i>: the template specialization shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>)</del><ins>The header 
<code>&lt;thread&gt;</code> provides a definition for a specialization of the 
template <code>hash&lt;thread::id&gt;</code>. The requirements for the members of this 
specialization are given in sub-clause 22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a></ins>.
</p>
</blockquote></blockquote>
</li>

</ol>
]</i></p>


<p><i>[2012, Portland: Move to Tentatively Ready]</i></p>

<p>
No further wording issues, so move to Tentatively Ready (post meeting issues processing).
</p>

<p><i>[2013-04-20 Bristol]</i></p>




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

<ol>
<li><p>Change 19.5.7 <a href="https://wg21.link/syserr.hash">[syserr.hash]</a> as indicated:</p>

<blockquote><pre>
template &lt;&gt; struct hash&lt;error_code&gt;;
</pre><blockquote>
<p>
-1- <del><i>Requires</i>: t</del><ins>T</ins>he template specialization shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>.
</p>
</blockquote></blockquote>
</li>

<li><p>Change 22.9.3 <a href="https://wg21.link/bitset.hash">[bitset.hash]</a> as indicated:</p>

<blockquote><pre>
template &lt;size_t N&gt; struct hash&lt;bitset&lt;N&gt; &gt;;
</pre><blockquote>
<p>
-1- <del><i>Requires</i>: t</del><ins>T</ins>he template specialization shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>).
</p>
</blockquote></blockquote>
</li>

<li><p>Change 20.3.3 <a href="https://wg21.link/util.smartptr.hash">[util.smartptr.hash]</a> as indicated:</p>

<blockquote><pre>
template &lt;class T, class D&gt; struct hash&lt;unique_ptr&lt;T, D&gt; &gt;;
</pre><blockquote>
<p>
-1- <del><i>Requires</i>: t</del><ins>T</ins>he template specialization shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>). For an object <code>p</code> of type 
<code>UP</code>, where <code>UP</code> is <code>unique_ptr&lt;T, D&gt;</code>, 
<code>hash&lt;UP&gt;()(p)</code> shall evaluate to the same value as 
<code>hash&lt;typename UP::pointer&gt;()(p.get())</code>.  <del>The specialization 
<code>hash&lt;typename UP::pointer&gt;</code> shall be well-formed.</del>
<p/>
<ins>-?- <i>Requires</i>: The specialization <code>hash&lt;typename UP::pointer&gt;</code> 
shall be well-formed and well-defined, and shall meet the requirements of class template
<code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>).</ins>
</p>
</blockquote></blockquote>

<blockquote><pre>
template &lt;class T&gt; struct hash&lt;shared_ptr&lt;T&gt; &gt;;
</pre><blockquote>
<p>
-2- <del><i>Requires</i>: t</del><ins>T</ins>he template specialization shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>). For an object <code>p</code> of type 
<code>shared_ptr&lt;T&gt;</code>, <code>hash&lt;shared_ptr&lt;T&gt; &gt;()(p)</code> 
shall evaluate to the same value as <code>hash&lt;T*&gt;()(p.get())</code>.
</p>
</blockquote></blockquote>
</li>

<li><p>Change 22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a> p2 as indicated: [<i>Comment</i>: For unknown
reasons the extended integer types are not mentioned here, which looks like an oversight to
me and makes also the wording more complicated. See <a href="lwg-defects.html#2119" title="Missing hash specializations for extended integer types (Status: C++17)">2119</a><sup><a href="https://cplusplus.github.io/LWG/issue2119" title="Latest snapshot">(i)</a></sup> for this part
of the problem. &mdash; <i>end comment</i>]</p>

<blockquote><pre>
template &lt;&gt; struct hash&lt;bool&gt;;
template &lt;&gt; struct hash&lt;char&gt;;
[&hellip;]
template &lt;&gt; struct hash&lt;long double&gt;;
template &lt;class T&gt; struct hash&lt;T*&gt;;
</pre><blockquote>
<p>
-2- <del><i>Requires</i>: t</del><ins>T</ins>he template specializations shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>).
</p>
</blockquote></blockquote>
</li>

<li><p>Change  [type.index.hash] p1 as indicated:</p>

<blockquote><pre>
template &lt;&gt; struct hash&lt;type_index&gt;;
</pre><blockquote>
<p>
-1- <del><i>Requires</i>: t</del><ins>T</ins>he template specialization shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>). For 
an object <code>index</code> of type <code>type_index</code>, <code>hash&lt;type_index&gt;()(index)</code> 
shall evaluate to the same result as <code>index.hash_code()</code>.
</p>
</blockquote></blockquote>
</li>

<li><p>Change 27.4.6 <a href="https://wg21.link/basic.string.hash">[basic.string.hash]</a> p1 as indicated:</p>

<blockquote><pre>
template &lt;&gt; struct hash&lt;string&gt;;
template &lt;&gt; struct hash&lt;u16string&gt;;
template &lt;&gt; struct hash&lt;u32string&gt;;
template &lt;&gt; struct hash&lt;wstring&gt;;
</pre><blockquote>
<p>
-1- <del><i>Requires</i>: t</del><ins>T</ins>he template specializations shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>).
</p>
</blockquote></blockquote>
</li>

<li><p>Change 23.3.14 <a href="https://wg21.link/vector.bool">[vector.bool]</a> p7 as indicated:</p>

<blockquote><pre>
template &lt;class Allocator&gt; struct hash&lt;vector&lt;bool, Allocator&gt; &gt;;
</pre><blockquote>
<p>
-7- <del><i>Requires</i>: t</del><ins>T</ins>he template specialization shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>).
</p>
</blockquote></blockquote>
</li>

<li><p>Change 32.4.3.2 <a href="https://wg21.link/thread.thread.id">[thread.thread.id]</a> p14 as indicated:</p>

<blockquote><pre>
template &lt;&gt; struct hash&lt;thread::id&gt;;
</pre><blockquote>
<p>
-14- <del><i>Requires</i>: t</del><ins>T</ins>he template specialization shall meet the requirements 
of class template <code>hash</code> (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>).
</p>
</blockquote></blockquote>
</li>

</ol>






</body>
</html>
