<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 638: deque end invalidation during erase</title>
<meta property="og:title" content="Issue 638: deque end invalidation during erase">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue638.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#CD1">CD1</a> status.</em></p>
<h3 id="638"><a href="lwg-defects.html#638">638</a>. <code>deque</code> end invalidation during erase</h3>
<p><b>Section:</b> 23.3.5.4 <a href="https://wg21.link/deque.modifiers">[deque.modifiers]</a> <b>Status:</b> <a href="lwg-active.html#CD1">CD1</a>
 <b>Submitter:</b> Steve LoBasso <b>Opened:</b> 2007-02-17 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#deque.modifiers">active issues</a> in [deque.modifiers].</p>
<p><b>View all other</b> <a href="lwg-index.html#deque.modifiers">issues</a> in [deque.modifiers].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The standard states at 23.3.5.4 <a href="https://wg21.link/deque.modifiers">[deque.modifiers]</a>/4:
</p>
<blockquote><pre>
deque erase(...)
</pre>
 <p>
<i>Effects:</i> ... An erase at either end of the deque invalidates only
the iterators and the references to the erased elements.
</p>
</blockquote>
<p>
This does not state that iterators to end will be invalidated.
It needs to be amended in such a way as to account for end invalidation.
</p>
<p>
Something like:
</p>
<blockquote><p>
Any time the last element is erased, iterators to end are invalidated.
</p></blockquote>

<p>
This would handle situations like:
</p>
<blockquote><pre>
erase(begin(), end())
erase(end() - 1)
pop_back()
resize(n, ...) where n &lt; size()
pop_front() with size() == 1

</pre></blockquote>

<p><i>[
Post Kona, Steve LoBasso notes:
]</i></p>


<blockquote><p>
My only issue with the proposed resolution is that it might not be clear
that <code>pop_front()</code> [where <code>size() == 1</code>] can invalidate past-the-end
iterators.
</p></blockquote>

<p><i>[
Kona (2007): Proposed wording added and moved to Review.
]</i></p>


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


<blockquote><p>
Note that there is existing code that relies on iterators not being
invalidated, but there are also existing implementations that do
invalidate iterators. Thus, such code is not portable in any case. There
is a <code>pop_front()</code> note, which should possibly be a separate issue. Mike
Spertus to evaluate and, if need be, file an issue.
</p></blockquote>



<p id="res-638"><b>Proposed resolution:</b></p>
<p>
Change 23.3.5.4 <a href="https://wg21.link/deque.modifiers">[deque.modifiers]</a>, p4:
</p>

<blockquote>
<pre>
iterator erase(const_iterator position); 
iterator erase(const_iterator first, const_iterator last);
</pre>

<blockquote>
<p>
-4- <i>Effects:</i> An erase in the middle of the <code>deque</code>
invalidates all the iterators and references to elements of the
<code>deque</code> <ins>and the past-the-end iterator</ins>. An erase at
either end of the <code>deque</code> invalidates only the iterators and the
references to the erased elements<ins>, except that erasing at the end
also invalidates the past-the-end iterator</ins>.
</p>
</blockquote>
</blockquote>






</body>
</html>
