<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1041: Add associative/unordered container functions that allow to extract elements</title>
<meta property="og:title" content="Issue 1041: Add associative/unordered container functions that allow to extract elements">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1041.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#Resolved">Resolved</a> status.</em></p>
<h3 id="1041"><a href="lwg-defects.html#1041">1041</a>. Add associative/unordered container functions that allow to extract elements</h3>
<p><b>Section:</b> 23.2.7 <a href="https://wg21.link/associative.reqmts">[associative.reqmts]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Alisdair Meredith <b>Opened:</b> 2009-03-12 <b>Last modified:</b> 2020-09-06</p>
<p><b>Priority: </b>Not Prioritized
</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#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>

<p><b>Addresses UK 239 [CD1]</b></p>

<p>
It is not possible to take a move-only key out of an unordered
container, such as (<code>multi</code>)<code>set</code> or
(<code>multi</code>)<code>map</code>, or the new unordered containers.
</p>

<p>
Add below <code>a.erase(q)</code>, <code>a.extract(q)</code>, with the following notation:
</p>
<p>
<code>a.extract(q)></code>, Return type <code>pair&lt;key, iterator&gt;</code>
Extracts the element pointed to by <code>q</code> and erases it from the
<code>set</code>. Returns a <code>pair</code> containing the value pointed to by
<code>q</code> and an <code>iterator</code> pointing to the element immediately
following <code>q</code> prior to the element being erased. If no such
element exists,returns <code>a.end()</code>.
</p>

<p><i>[
Summit:
]</i></p>


<blockquote><p>
We look forward to a paper on this topic. We recommend no action until a
paper is available. The paper would need to address exception safety.
</p></blockquote>

<p><i>[
Post Summit Alisdair adds:
]</i></p>


<blockquote><p>
Would <code>value_type</code> be a better return type than <code>key_type</code>?
</p></blockquote>

<p><i>[
2009-07 post-Frankfurt:
]</i></p>


<blockquote><p>
Leave Open. Alisdair to contact Chris Jefferson about this.
</p></blockquote>

<p><i>[
2009-09-20 Howard adds:
]</i></p>


<blockquote><p>
See the 2009-09-19 comment of <a href="lwg-defects.html#839" title="Maps and sets missing splice operation (Status: Resolved)">839</a><sup><a href="https://cplusplus.github.io/LWG/issue839" title="Latest snapshot">(i)</a></sup> for an API which
accomplishes this functionality and also addresses several other use
cases which this proposal does not.
</p></blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Mark as NAD Future. No consensus to make the change at this time.
</p></blockquote>

<p><strong>Original resolution [SUPERSEDED]:</strong></p>
<blockquote class = "note">
<p>
In 23.2.7 <a href="https://wg21.link/associative.reqmts">[associative.reqmts]</a> Table 85, add:
</p>

<blockquote>
<table border="1">
<caption>Table 85 --  Associative container requirements (in addition to container)</caption>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Assertion/note<br/>pre-/post-condition</th>
<th>Complexity</th>
</tr>
<tr>
<td><code>a.erase(q)</code></td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr>
<td><ins><code>a.extract(q)</code></ins></td>
<td><ins><code>pair&lt;key_type, iterator&gt;</code></ins></td>
<td><ins>Extracts the element pointed to by <code>q</code> and erases it from the <code>set</code>. 
Returns a <code>pair</code> containing the value pointed to by <code>q</code> and an <code>iterator</code>
pointing to the element immediately following <code>q</code> prior to the element being
erased. If no such element 
exists, returns <code>a.end()</code>.</ins></td>
<td><ins>amortized constant</ins></td>
</tr>
</table>
</blockquote>

<p>
In 23.2.8 <a href="https://wg21.link/unord.req">[unord.req]</a> Table 87, add:
</p>

<blockquote>
<table border="1">
<caption>Table 87 -- Unordered associative container requirements (in addition to container)</caption>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Assertion/note<br/>pre-/post-condition</th>
<th>Complexity</th>
</tr>
<tr>
<td><code>a.erase(q)</code></td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr>
<td><ins><code>a.extract(q)</code></ins></td>
<td><ins><code>pair&lt;key_type, iterator&gt;</code></ins></td>
<td><ins>Extracts the element pointed to by <code>q</code> and erases it from the <code>set</code>. 
Returns a <code>pair</code> containing the value pointed to by <code>q</code> and an <code>iterator</code>
pointing to the element immediately following <code>q</code> prior to the element being
erased. If no such element 
exists, returns <code>a.end()</code>.</ins></td>
<td><ins>amortized constant</ins></td>
</tr>
</table>
</blockquote>
</blockquote>

<p><i>[08-2016, Post-Chicago]</i></p>

<p>Move to Tentatively Resolved</p>


<p id="res-1041"><b>Proposed resolution:</b></p>
<p>This functionality is provided by <a href="https://wg21.link/p0083r3">P0083R3</a></p>





</body>
</html>
