<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 250: splicing invalidates iterators</title>
<meta property="og:title" content="Issue 250: splicing invalidates iterators">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue250.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="250"><a href="lwg-defects.html#250">250</a>. splicing invalidates iterators</h3>
<p><b>Section:</b> 23.3.11.5 <a href="https://wg21.link/list.ops">[list.ops]</a> <b>Status:</b> <a href="lwg-active.html#CD1">CD1</a>
 <b>Submitter:</b> Brian Parker  <b>Opened:</b> 2000-07-14 <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#list.ops">issues</a> in [list.ops].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Section 23.3.11.5 <a href="https://wg21.link/list.ops">[list.ops]</a> states that
</p>
<pre>
  void splice(iterator position, list&lt;T, Allocator&gt;&amp; x);
</pre>
<p>
<i>invalidates</i> all iterators and references to list <code>x</code>.
</p>

<p>
This is unnecessary and defeats an important feature of splice. In
fact, the SGI STL guarantees that iterators to <code>x</code> remain valid
after <code>splice</code>.
</p>


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

<p>Add a footnote to 23.3.11.5 <a href="https://wg21.link/list.ops">[list.ops]</a>, paragraph 1:</p>
<blockquote><p>
[<i>Footnote:</i> As specified in  [default.con.req], paragraphs
4-5, the semantics described in this clause applies only to the case
where allocators compare equal.  --end footnote]
</p></blockquote>

<p>In 23.3.11.5 <a href="https://wg21.link/list.ops">[list.ops]</a>, replace paragraph 4 with:</p>
<blockquote><p>
Effects: Inserts the contents of x before position and x becomes 
empty.  Pointers and references to the moved elements of x now refer to 
those same elements but as members of *this.  Iterators referring to the 
moved elements will continue to refer to their elements, but they now 
behave as iterators into *this, not into x.
</p></blockquote>

<p>In 23.3.11.5 <a href="https://wg21.link/list.ops">[list.ops]</a>, replace paragraph 7 with:</p>
<blockquote><p>
Effects: Inserts an element pointed to by i from list x before 
position and removes the element from x. The result is unchanged if 
position == i or position == ++i.  Pointers and references to *i continue 
to refer to this same element but as a member of *this.  Iterators to *i 
(including i itself) continue to refer to the same element, but now 
behave as iterators into *this, not into x.
</p></blockquote>

<p>In 23.3.11.5 <a href="https://wg21.link/list.ops">[list.ops]</a>, replace paragraph 12 with:</p>
<blockquote><p>
Requires: [first, last) is a valid range in x. The result is 
undefined if position is an iterator in the range [first, last).  
Pointers and references to the moved elements of x now refer to those 
same elements but as members of *this.  Iterators referring to the moved 
elements will continue to refer to their elements, but they now behave as 
iterators into *this, not into x.
</p></blockquote>

<p><i>[pre-Copenhagen: Howard provided wording.]</i></p>



<p><b>Rationale:</b></p>
<p>The original proposed resolution said that iterators and references
would remain "valid".  The new proposed resolution clarifies what that
means.  Note that this only applies to the case of equal allocators.
From  [default.con.req] paragraph 4, the behavior of list when
allocators compare nonequal is outside the scope of the standard.</p>




</body>
</html>
