<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1133: Does N2844 break current specification of list::splice?</title>
<meta property="og:title" content="Issue 1133: Does N2844 break current specification of list::splice?">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1133.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#C++11">C++11</a> status.</em></p>
<h3 id="1133"><a href="lwg-defects.html#1133">1133</a>. Does N2844 break current specification of list::splice?</h3>
<p><b>Section:</b> 23.3.7.6 <a href="https://wg21.link/forward.list.ops">[forward.list.ops]</a>, 23.3.11.5 <a href="https://wg21.link/list.ops">[list.ops]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Alisdair Meredith <b>Opened:</b> 2009-05-09 <b>Last modified:</b> 2023-02-07</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#forward.list.ops">issues</a> in [forward.list.ops].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>
<p>
IIUC,
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2844.html">N2844</a>
means that lvalues will no longer bind to rvalue references.
Therefore, the current specification of <code>list::splice</code> (list
operations 23.3.11.5 <a href="https://wg21.link/list.ops">[list.ops]</a>) will be a breaking change of behaviour for existing
programs.  That is because we changed the signature to swallow via an rvalue
reference rather than the lvalue reference used in 03.
</p>
<p>
Retaining this form would be safer, requiring an explicit move when splicing
from lvalues.  However, this will break existing programs.
We have the same problem with <code>forward_list</code>, although without the risk of
breaking programs so here it might be viewed as a positive feature.
</p>
<p>
The problem signatures:
</p>
<blockquote><pre>
void splice_after(const_iterator position, forward_list&lt;T,Alloc&gt;&amp;&amp; x);
void splice_after(const_iterator position, forward_list&lt;T,Alloc&gt;&amp;&amp; x,
                  const_iterator i);
void splice_after(const_iterator position, forward_list&lt;T,Alloc&gt;&amp;&amp; x,
                  const_iterator first, const_iterator last);

void splice(const_iterator position, list&lt;T,Alloc&gt;&amp;&amp; x);
void splice(const_iterator position, list&lt;T,Alloc&gt;&amp;&amp; x,
            const_iterator i);
void splice(const_iterator position, list&lt;T,Alloc&gt;&amp;&amp; x,
            const_iterator first, const_iterator last);
</pre></blockquote>

<p>
<b>Possible resolutions:</b>
</p>

<p>
Option A.   Add an additional (non-const) lvalue-reference
overload in each case
</p>
<p>
Option B.   Change rvalue reference back to (non-const)
lvalue-reference overload in each case
</p>
<p>
Option C.   Add an additional (non-const) lvalue-reference
overload in just the <code>std::list</code> cases
</p>
<p>
I think (B) would be very unfortunate, I really like the <code>forward_list</code>
behaviour in (C) but feel (A) is needed for consistency.
</p>
<p>
My actual preference would be NAD, ship with this as a breaking change as it
is a more explicit interface.  I don't think that will fly though!
</p>

<p>
See the thread starting with c++std-lib-23725 for more discussion.
</p>

<p><i>[
2009-10-27 Christopher Jefferson provides proposed wording for Option C.
]</i></p>


<p><i>[
2009-12-08 Jonathan Wakely adds:
]</i></p>


<blockquote>
<p>
As Bill Plauger pointed out, <code>list::merge</code> needs similar treatment.
</p>
<p><i>[
Wording updated.
]</i></p>

</blockquote>

<p><i>[
2009-12-13 Moved to Tentatively Ready after 5 positive votes on c++std-lib.
]</i></p>



<p id="res-1133"><b>Proposed resolution:</b></p>
<p>
In 23.3.11 <a href="https://wg21.link/list">[list]</a>
</p>

<p>
Add lvalue overloads before rvalue ones:
</p>

<blockquote><pre>
<ins>void splice(const_iterator position, list&lt;T,Allocator&gt;&amp; x);</ins>
void splice(const_iterator position, list&lt;T,Allocator&gt;&amp;&amp; x);
<ins>void splice(const_iterator position, list&lt;T,Allocator&gt;&amp; x, const_iterator i);</ins>
void splice(const_iterator position, list&lt;T,Allocator&gt;&amp;&amp; x, const_iterator i);
<ins>void splice(const_iterator position, list&lt;T,Allocator&gt;&amp; x,
            const_iterator first, const_iterator last);</ins>
void splice(const_iterator position, list&lt;T,Allocator&gt;&amp;&amp; x,
            const_iterator first, const_iterator last);
<ins>void merge(list&lt;T,Allocator&gt;&amp; x);
template &lt;class Compare&gt; void merge(list&lt;T,Allocator&gt;&amp; x, Compare comp);</ins>
void merge(list&lt;T,Allocator&gt;&amp;&amp; x);
template &lt;class Compare&gt; void merge(list&lt;T,Allocator&gt;&amp;&amp; x, Compare comp);

</pre></blockquote>

<p>
In 23.3.11.5 <a href="https://wg21.link/list.ops">[list.ops]</a>, similarly add lvalue overload before each rvalue one:
</p>
<p>
(After paragraph 2)
</p>

<blockquote><pre>
<ins>void splice(const_iterator position, list&lt;T,Allocator&gt;&amp; x);</ins>
void splice(const_iterator position, list&lt;T,Allocator&gt;&amp;&amp; x);
</pre></blockquote>

<p>
(After paragraph 6)
</p>

<blockquote><pre>
<ins>void splice(const_iterator position, list&lt;T,Allocator&gt;&amp; x, const_iterator i);</ins>
void splice(const_iterator position, list&lt;T,Allocator&gt;&amp;&amp; x, <ins>const_</ins>iterator i);
</pre></blockquote>

<p>
(After paragraph 10)
</p>

<blockquote><pre>
<ins>void splice(const_iterator position, list&lt;T,Allocator&gt;&amp; x,
            const_iterator first, const_iterator last);</ins>
void splice(const_iterator position, list&lt;T,Allocator&gt;&amp;&amp; x,
            <ins>const_</ins>iterator first, <ins>const_</ins>iterator last);
</pre></blockquote>

<p>
In 23.3.11.5 <a href="https://wg21.link/list.ops">[list.ops]</a>, after paragraph 21
</p>

<blockquote><pre>
<ins>void merge(list&lt;T,Allocator&gt;&amp; x);
template &lt;class Compare&gt; void merge(list&lt;T,Allocator&gt;&amp; x, Compare comp);</ins>
void merge(list&lt;T,Allocator&gt;&amp;&amp; x);
template &lt;class Compare&gt; void merge(list&lt;T,Allocator&gt;&amp;&amp; x, Compare comp);
</pre></blockquote>






</body>
</html>
