<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2844: Stability of a_uniq.insert(i, j)</title>
<meta property="og:title" content="Issue 2844: Stability of a_uniq.insert(i, j)">
<meta property="og:description" content="C++ library issue. Status: Open">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2844.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#Open">Open</a> status.</em></p>
<h3 id="2844"><a href="lwg-active.html#2844">2844</a>. Stability of <code>a_uniq.insert(i, j)</code></h3>
<p><b>Section:</b> 23.2.7 <a href="https://wg21.link/associative.reqmts">[associative.reqmts]</a>, 23.2.8 <a href="https://wg21.link/unord.req">[unord.req]</a> <b>Status:</b> <a href="lwg-active.html#Open">Open</a>
 <b>Submitter:</b> Matt Austern <b>Opened:</b> 2016-12-14 <b>Last modified:</b> 2020-02-14</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#associative.reqmts">active issues</a> in [associative.reqmts].</p>
<p><b>View all other</b> <a href="lwg-index.html#associative.reqmts">issues</a> in [associative.reqmts].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Open">Open</a> status.</p>
<p><b>Discussion:</b></p>
<p>
If we write <code>a_uniq.insert(i, j)</code> and <code>[i, j)</code> has multiple elements with keys that compare equivalent, 
which ones get inserted? Consider, for example, inserting into a <code>map&lt;string, int&gt;</code> with
</p>
<blockquote><pre>
m.insert({{"red", 5}, {"green", 3}, {"red", 7}, {"blue", 2}, {"pink", 6}});
</pre></blockquote>
<p>
Which value for <code>"red"</code> will the map have?
<p/>
On my implementation we got <code>"red" -&gt; 5</code>, and I suspect that's true on most or all implementations, but I don't believe 
that's guaranteed by anything in the requirements. The wording in Table 90 just says that it "inserts each element from 
the range <code>[i, j)</code> if and only if there is no element with key equivalent to the key of that element", but that 
doesn't tell us what happens if <code>[i, j)</code> contains duplicate keys because it doesn't say what order the insertions 
are performed in. The standard should either guarantee that the first value is the one that gets inserted, or explicitly 
say that this is unspecified.
<p/>
The same issue applies to the range constructor, and to the unordered associative containers.
</p>

<p><i>[2017-01-27 Telecon]</i></p>

<p>Priority 3; Nico to provide wording.</p>

<p><i>[2020-02-14, Prague]</i></p>

<p>
LWG discussion. Suggestion to specify that we like the direction of the wording for <code>insert</code> of
unordered containers, but would also like to clarify that the loop is meant to be "in order" of the 
sequence elements.
<p/>
Daniel K. volunteered to provide such wording.
</p>


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





</body>
</html>
