<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1111: associative containers underconstrained</title>
<meta property="og:title" content="Issue 1111: associative containers underconstrained">
<meta property="og:description" content="C++ library issue. Status: NAD Concepts">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1111.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#NAD_Concepts">NAD Concepts</a> status.</em></p>
<h3 id="1111"><a href="lwg-closed.html#1111">1111</a>. associative containers underconstrained</h3>
<p><b>Section:</b> 23.4 <a href="https://wg21.link/associative">[associative]</a> <b>Status:</b> <a href="lwg-active.html#NAD_Concepts">NAD Concepts</a>
 <b>Submitter:</b> Alisdair Meredith <b>Opened:</b> 2009-04-29 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#associative">issues</a> in [associative].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD Concepts">NAD Concepts</a> status.</p>
<p><b>Discussion:</b></p>
<p>
According to table 87 (n2857) the expression <code>X::key_equal</code> for an unordered
container shall return a value of type <code>Pred</code>, where <code>Pred</code> is an equivalence
relation.
</p>

<p>
However, all 4 containers constrain <code>Pred</code> to be merely a <code>Predicate</code>,
and not <code>EquivalenceRelation</code>.
</p>

<p><i>[
Batavia (2009-05):
]</i></p>

<blockquote>
<p>
We agree with the proposed resolution.
</p>
<p>
Move to Review.
</p>
</blockquote>


<p id="res-1111"><b>Proposed resolution:</b></p>
<p>
For ordered containers, replace 
</p>
<blockquote><pre>
Predicate&lt;auto, Key, Key&gt; Compare = less&lt;Key&gt;
</pre></blockquote>
<p>
with 
</p>
<blockquote><pre>
StrictWeakOrder&lt;auto, Key, Key&gt; Compare = less&lt;Key&gt;
</pre></blockquote>

<p>
For unordered containers, replace 
</p>
<blockquote><pre>
Predicate&lt;auto, Key, Key&gt; Compare = less&lt;Key&gt;
</pre></blockquote>
<p>
with 
</p>
<blockquote><pre>
EquivalenceRelation&lt;auto, Key, Key&gt; Compare = less&lt;Key&gt;
</pre></blockquote>
<p>
As in the following declarations:
</p>

<blockquote>
<p>
Associative containers 23.4 <a href="https://wg21.link/associative">[associative]</a>
</p>
<p>
 1 Headers <code>&lt;map&gt;</code> and <code>&lt;set&gt;</code>:
</p>
<p>
   Header <code>&lt;map&gt;</code> synopsis
</p>
<blockquote><pre>
   namespace std {
     template &lt;ValueType Key, ValueType T,
               <del>Predicate</del><ins>StrictWeakOrder</ins>&lt;auto, Key<del>, Key</del>&gt; Compare = less&lt;Key&gt;,
               Allocator Alloc = allocator&lt;pair&lt;const Key, T&gt; &gt; &gt;
       requires NothrowDestructible&lt;Key&gt; &amp;&amp; NothrowDestructible&lt;T&gt;
             &amp;&amp; CopyConstructible&lt;Compare&gt;
             &amp;&amp; AllocatableElement&lt;Alloc, Compare, const Compare&amp;&gt;
             &amp;&amp; AllocatableElement&lt;Alloc, Compare, Compare&amp;&amp;&gt;
     class map;

     ...

     template &lt;ValueType Key, ValueType T,
               <del>Predicate</del><ins>StrictWeakOrder</ins>&lt;auto, Key<del>, Key</del>&gt; Compare = less&lt;Key&gt;,
               Allocator Alloc = allocator&lt;pair&lt;const Key, T&gt; &gt; &gt;
       requires NothrowDestructible&lt;Key&gt; &amp;&amp; NothrowDestructible&lt;T&gt;
             &amp;&amp; CopyConstructible&lt;Compare&gt;
             &amp;&amp; AllocatableElement&lt;Alloc, Compare, const Compare&amp;&gt;
             &amp;&amp; AllocatableElement&lt;Alloc, Compare, Compare&amp;&amp;&gt;
     class multimap;

     ...

   }
</pre></blockquote>

<p>
   Header &lt;set&gt; synopsis
</p>
<blockquote><pre>
   namespace std {
     template &lt;ValueType Key, <del>Predicate</del><ins>StrictWeakOrder</ins>&lt;auto, Key<del>, Key</del>&gt; Compare = less&lt;Key&gt;,
               Allocator Alloc = allocator&lt;Key&gt; &gt;
       requires NothrowDestructible&lt;Key&gt; &amp;&amp; CopyConstructible&lt;Compare&gt;
             &amp;&amp; AllocatableElement&lt;Alloc, Compare, const Compare&amp;&gt;
             &amp;&amp; AllocatableElement&lt;Alloc, Compare, Compare&amp;&amp;&gt;
     class set;

     ...

     template &lt;ValueType Key, <del>Predicate</del><ins>StrictWeakOrder</ins>&lt;auto, Key<del>, Key</del>&gt; Compare = less&lt;Key&gt;,
               Allocator Alloc = allocator&lt;Key&gt; &gt;
       requires NothrowDestructible&lt;Key&gt; &amp;&amp; CopyConstructible&lt;Compare&gt;
             &amp;&amp; AllocatableElement&lt;Alloc, Compare, const Compare&amp;&gt;
             &amp;&amp; AllocatableElement&lt;Alloc, Compare, Compare&amp;&amp;&gt;
     class multiset;

     ...

   }
</pre></blockquote>

<p>
 23.4.1p2 Class template map [map]
</p>
<blockquote><pre>
 namespace std {
   template &lt;ValueType Key, ValueType T,
             <del>Predicate</del><ins>StrictWeakOrder</ins>&lt;auto, Key<del>, Key</del>&gt; Compare = less&lt;Key&gt;,
             Allocator Alloc = allocator&lt;pair&lt;const Key, T&gt; &gt; &gt;
     requires NothrowDestructible&lt;Key&gt; &amp;&amp; NothrowDestructible&lt;T&gt;
           &amp;&amp; CopyConstructible&lt;Compare&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Compare, const Compare&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Compare, Compare&amp;&amp;&gt;
   class map {
     ...
   };
 }
</pre></blockquote>


<p>
 23.4.2p2 Class template multimap [multimap]
</p>
<blockquote><pre>
 namespace std {
   template &lt;ValueType Key, ValueType T,
             <del>Predicate</del><ins>StrictWeakOrder</ins>&lt;auto, Key<del>, Key</del>&gt; Compare = less&lt;Key&gt;,
             Allocator Alloc = allocator&lt;pair&lt;const Key, T&gt; &gt; &gt;
     requires NothrowDestructible&lt;Key&gt; &amp;&amp; NothrowDestructible&lt;T&gt;
           &amp;&amp; CopyConstructible&lt;Compare&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Compare, const Compare&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Compare, Compare&amp;&amp;&gt;
   class multimap {
     ...
   };
 }
</pre></blockquote>


<p>
 23.4.3p2 Class template set [set]
</p>
<blockquote><pre>
 namespace std {
   template &lt;ValueType Key, <del>Predicate</del><ins>StrictWeakOrder</ins>&lt;auto, Key<del>, Key</del>&gt; Compare = less&lt;Key&gt;,
             Allocator Alloc = allocator&lt;Key&gt; &gt;
     requires NothrowDestructible&lt;Key&gt; &amp;&amp; CopyConstructible&lt;Compare&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Compare, const Compare&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Compare, Compare&amp;&amp;&gt;
   class set {
     ...
   };
 }
</pre></blockquote>


<p>
 23.4.4p2 Class template multiset [multiset]
</p>
<blockquote><pre>
 namespace std {
   template &lt;ValueType Key, <del>Predicate</del><ins>StrictWeakOrder</ins>&lt;auto, Key<del>, Key</del>&gt; Compare = less&lt;Key&gt;,
             Allocator Alloc = allocator&lt;Key&gt; &gt;
     requires NothrowDestructible&lt;Key&gt; &amp;&amp; CopyConstructible&lt;Compare&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Compare, const Compare&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Compare, Compare&amp;&amp;&gt;
   class multiset {
     ...
   };
 }
</pre></blockquote>

<p>
 23.5 Unordered associative containers [unord]
</p>
<p>
 1 Headers &lt;unordered_map&gt; and &lt;unordered_set&gt;:
</p>
<p>
 Header &lt;unordered_map&gt; synopsis
</p>
<blockquote><pre>
 namespace std {
   // 23.5.1, class template unordered_map:
   template &lt;ValueType Key,
             ValueType T,
             Callable&lt;auto, const Key&amp;&gt; Hash = hash&lt;Key&gt;,
             <del>Predicate</del><ins>EquivalenceRelation</ins>&lt;auto, Key<del>, Key</del>&gt; Pred = equal_to&lt;Key&gt;,
             Allocator Alloc = allocator&lt;pair&lt;const Key, T&gt; &gt; &gt;
     requires NothrowDestructible&lt;Key&gt; &amp;&amp; NothrowDestructible&lt;T&gt;
           &amp;&amp; SameType&lt;Hash::result_type, size_t&gt;
           &amp;&amp; CopyConstructible&lt;Hash&gt; &amp;&amp; CopyConstructible&lt;Pred&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, const Pred&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, Pred&amp;&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, const Hash&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, Hash&amp;&amp;&gt;
     class unordered_map;

   // 23.5.2, class template unordered_multimap:
   template &lt;ValueType Key,
             ValueType T,
             Callable&lt;auto, const Key&amp;&gt; Hash = hash&lt;Key&gt;,
             <del>Predicate</del><ins>EquivalenceRelation</ins>&lt;auto, Key<del>, Key</del>&gt; Pred = equal_to&lt;Key&gt;,
             Allocator Alloc = allocator&lt;pair&lt;const Key, T&gt; &gt; &gt;
     requires NothrowDestructible&lt;Key&gt; &amp;&amp; NothrowDestructible&lt;T&gt;
           &amp;&amp; SameType&lt;Hash::result_type, size_t&gt;
           &amp;&amp; CopyConstructible&lt;Hash&gt; &amp;&amp; CopyConstructible&lt;Pred&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, const Pred&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, Pred&amp;&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, const Hash&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, Hash&amp;&amp;&gt;
     class unordered_multimap;

   ...
 }
</pre></blockquote>

<p>
 Header &lt;unordered_set&gt; synopsis
</p>
<blockquote><pre>
 namespace std {
   // 23.5.3, class template unordered_set:
   template &lt;ValueType Value,
             Callable&lt;auto, const Value&amp;&gt; Hash = hash&lt;Value&gt;,
             <del>Predicate</del><ins>EquivalenceRelation</ins>&lt;auto, Value<del>, Value</del>&gt; class Pred = equal_to&lt;Value&gt;,
             Allocator Alloc = allocator&lt;Value&gt; &gt;
     requires NothrowDestructible&lt;Value&gt;
           &amp;&amp; SameType&lt;Hash::result_type, size_t&gt;
           &amp;&amp; CopyConstructible&lt;Hash&gt; &amp;&amp; CopyConstructible&lt;Pred&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, const Pred&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, Pred&amp;&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, const Hash&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, Hash&amp;&amp;&gt;
     class unordered_set;

   // 23.5.4, class template unordered_multiset:
   template &lt;ValueType Value,
             Callable&lt;auto, const Value&amp;&gt; Hash = hash&lt;Value&gt;,
             <del>Predicate</del><ins>EquivalenceRelation</ins>&lt;auto, Value<del>, Value</del>&gt; class Pred = equal_to&lt;Value&gt;,
             Allocator Alloc = allocator&lt;Value&gt; &gt;
     requires NothrowDestructible&lt;Value&gt;
           &amp;&amp; SameType&lt;Hash::result_type, size_t&gt;
           &amp;&amp; CopyConstructible&lt;Hash&gt; &amp;&amp; CopyConstructible&lt;Pred&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, const Pred&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, Pred&amp;&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, const Hash&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, Hash&amp;&amp;&gt;
     class unordered_multiset;

   ...
 }
</pre></blockquote>

<p>
 23.5.1p3 Class template unordered_map [unord.map]
</p>
<blockquote><pre>
 namespace std {
   template &lt;ValueType Key,
             ValueType T,
             Callable&lt;auto, const Key&amp;&gt; Hash = hash&lt;Key&gt;,
             <del>Predicate</del><ins>EquivalenceRelation</ins>&lt;auto, Key<del>, Key</del>&gt; Pred = equal_to&lt;Key&gt;,
             Allocator Alloc = allocator&lt;pair&lt;const Key, T&gt; &gt; &gt;
     requires NothrowDestructible&lt;Key&gt; &amp;&amp; NothrowDestructible&lt;T&gt;
           &amp;&amp; SameType&lt;Hash::result_type, size_t&gt;
           &amp;&amp; CopyConstructible&lt;Hash&gt; &amp;&amp; CopyConstructible&lt;Pred&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, const Pred&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, Pred&amp;&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, const Hash&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, Hash&amp;&amp;&gt;
   class unordered_map
   {
     ...
   };
 }
</pre></blockquote>

<p>
 23.5.2p3 Class template unordered_multimap [unord.multimap]
</p>
<blockquote><pre>
 namespace std {
   template &lt;ValueType Key,
             ValueType T,
             Callable&lt;auto, const Key&amp;&gt; Hash = hash&lt;Key&gt;,
             <del>Predicate</del><ins>EquivalenceRelation</ins>&lt;auto, Key<del>, Key</del>&gt; Pred = equal_to&lt;Key&gt;,
             Allocator Alloc = allocator&lt;pair&lt;const Key, T&gt; &gt; &gt;
     requires NothrowDestructible&lt;Key&gt; &amp;&amp; NothrowDestructible&lt;T&gt;
           &amp;&amp; SameType&lt;Hash::result_type, size_t&gt;
           &amp;&amp; CopyConstructible&lt;Hash&gt; &amp;&amp; CopyConstructible&lt;Pred&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, const Pred&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, Pred&amp;&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, const Hash&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, Hash&amp;&amp;&gt;
   class unordered_multimap
   {
     ...
   };
 }
</pre></blockquote>

<p>
 23.5.3p3 Class template unordered_set [unord.set]
</p>
<blockquote><pre>
 namespace std {
   template &lt;ValueType Value,
             Callable&lt;auto, const Value&amp;&gt; Hash = hash&lt;Value&gt;,
             <del>Predicate</del><ins>EquivalenceRelation</ins>&lt;auto, Value<del>, Value</del>&gt; class Pred = equal_to&lt;Value&gt;,
             Allocator Alloc = allocator&lt;Value&gt; &gt;
     requires NothrowDestructible&lt;Value&gt;
           &amp;&amp; SameType&lt;Hash::result_type, size_t&gt;
           &amp;&amp; CopyConstructible&lt;Hash&gt; &amp;&amp; CopyConstructible&lt;Pred&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, const Pred&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, Pred&amp;&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, const Hash&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, Hash&amp;&amp;&gt;
   class unordered_set
   {
     ...
   };
 }
</pre></blockquote>
<p>
 23.5.4p3 Class template unordered_multiset [unord.multiset]
</p>
<blockquote><pre>
 namespace std {
   template &lt;ValueType Value,
             Callable&lt;auto, const Value&amp;&gt; Hash = hash&lt;Value&gt;,
             <del>Predicate</del><ins>EquivalenceRelation</ins>&lt;auto, Value<del>, Value</del>&gt; class Pred = equal_to&lt;Value&gt;,
             Allocator Alloc = allocator&lt;Value&gt; &gt;
     requires NothrowDestructible&lt;Value&gt;
           &amp;&amp; SameType&lt;Hash::result_type, size_t&gt;
           &amp;&amp; CopyConstructible&lt;Hash&gt; &amp;&amp; CopyConstructible&lt;Pred&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, const Pred&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Pred, Pred&amp;&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, const Hash&amp;&gt;
           &amp;&amp; AllocatableElement&lt;Alloc, Hash, Hash&amp;&amp;&gt;
   class unordered_multiset
   {
     ...
   };
 }
</pre></blockquote>

</blockquote>






</body>
</html>
