<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3742: deque::prepend_range needs to permute</title>
<meta property="og:title" content="Issue 3742: deque::prepend_range needs to permute">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3742.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++23">C++23</a> status.</em></p>
<h3 id="3742"><a href="lwg-defects.html#3742">3742</a>. <code>deque::prepend_range</code> needs to permute</h3>
<p><b>Section:</b> 23.2.4 <a href="https://wg21.link/sequence.reqmts">[sequence.reqmts]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Casey Carter <b>Opened:</b> 2022-07-16 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>2
</p>
<p><b>View other</b> <a href="lwg-index-open.html#sequence.reqmts">active issues</a> in [sequence.reqmts].</p>
<p><b>View all other</b> <a href="lwg-index.html#sequence.reqmts">issues</a> in [sequence.reqmts].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
When the range to be inserted is neither bidirectional nor sized, it's simpler to prepend 
elements one at a time, and then reverse the prepended elements. When the range to be 
inserted is neither forward nor sized, I believe this approach is necessary to implement 
<code>prepend_range</code> at all &mdash; there is no way to determine the length of the range 
modulo the block size of the <code>deque</code> ahead of time so as to insert the new elements 
in the proper position.
<p/>
The container requirements do not allow <code>prepend_range</code> to permute elements in a 
<code>deque</code>. I believe we <em>must</em> allow permutation when the range is neither 
forward nor sized, and we <em>should</em> allow permutation when the range is not bidirectional 
to allow implementations the freedom to make a single pass through the range.
</p>

<p><i>[2022-07-17; Daniel comments]</i></p>

<p>
The below suggested wording follows the existing style used in the specification of <code>insert</code>
and <code>insert_range</code>, for example. Unfortunately, this existing practice violates the usual
wording style that a <i>Cpp17XXX</i> requirement shall be <em>met</em> and that we should better
say that "lvalues of type <code>T</code> are swappable (16.4.4.3 <a href="https://wg21.link/swappable.requirements">[swappable.requirements]</a>)" to 
be clearer about the specific swappable context. A separate editorial issue will be reported to take
care of this problem.
</p>

<p><i>[2022-08-23; Reflector poll]</i></p>

<p>
Set status to Tentatively Ready after five votes in favour during reflector poll.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to <a href="https://wg21.link/N4910" title=" Working Draft, Standard for Programming Language C++">N4910</a>.
</p>

<ol>
<li><p>Modify 23.2.4 <a href="https://wg21.link/sequence.reqmts">[sequence.reqmts]</a> as indicated:</p>

<blockquote>
<pre>
a.prepend_range(rg)
</pre>
<blockquote>
<p>
-94- <i>Result:</i> <code>void</code>
<p/>
-95- <i>Preconditions:</i> <code>T</code> is <i>Cpp17EmplaceConstructible</i> into <code>X</code> 
from <code>*ranges::begin(rg)</code>. <ins>For <code>deque</code>, <code>T</code> is also 
<code>Cpp17MoveInsertable</code> into <code>X</code>, <i>Cpp17MoveConstructible</i>, 
<i>Cpp17MoveAssignable</i>, and swappable (16.4.4.3 <a href="https://wg21.link/swappable.requirements">[swappable.requirements]</a>).</ins>
<p/>
-96- <i>Effects:</i> Inserts copies of elements in <code>rg</code> before <code>begin()</code>. 
Each iterator in the range <code>rg</code> is dereferenced exactly once.
<p/>
[<i>Note 3</i>: The order of elements in <code>rg</code> is not reversed. &mdash; <i>end note</i>]
<p/>
-97- <i>Remarks:</i> Required for <code>deque</code>, <code>forward_list</code>, and <code>list</code>.
</p>
</blockquote>
</blockquote>
</li>

</ol>
</blockquote>

<p><i>[2022-11-07; Daniel reopens and comments]</i></p>

<p>
The proposed wording has two problems:
</p>
<ol>
<li><p>It still uses "swappable" instead of "swappable lvalues", which
with the (informal) acceptance of <a href="https://isocpp.org/files/papers/P2696R0.html">P2696R0</a>
should now become <i>Cpp17Swappable</i>.</p></li>
<li><p>It uses an atypical form to say "<code>T</code> (is) <i>Cpp17MoveConstructible</i>,
<i>Cpp17MoveAssignable</i>" instead of the more correct form "<code>T</code> meets the
<i>Cpp17MoveConstructible</i> and <i>Cpp17MoveAssignable</i> requirements". This
form was also corrected by <a href="https://isocpp.org/files/papers/P2696R0.html">P2696R0</a>.</p></li>
</ol>
<p>
The revised wording uses the <a href="https://isocpp.org/files/papers/P2696R0.html">P2696R0</a>
wording approach to fix both problems.
</p>

<p><i>[Kona 2022-11-12; Set priority to 2]</i></p>



<p><i>[2022-11-30; Reflector poll]</i></p>

<p>
Set status to Tentatively Ready after five votes in favour during reflector poll.
</p>

<p><i>[2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Voting &rarr; WP.]</i></p>



<p id="res-3742"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4917" title=" Working Draft, Standard for Programming Language C++">N4917</a> <b>assuming that <a href="https://isocpp.org/files/papers/P2696R0.html">P2696R0</a>
has been accepted</b>.
</p>

<ol>
<li><p>Modify 23.2.4 <a href="https://wg21.link/sequence.reqmts">[sequence.reqmts]</a> as indicated:</p>

<blockquote>
<pre>
a.prepend_range(rg)
</pre>
<blockquote>
<p>
-94- <i>Result:</i> <code>void</code>
<p/>
-95- <i>Preconditions:</i> <code>T</code> is <i>Cpp17EmplaceConstructible</i> into <code>X</code> 
from <code>*ranges::begin(rg)</code>. <ins>For <code>deque</code>, <code>T</code> is also 
<code>Cpp17MoveInsertable</code> into <code>X</code>, and <code>T</code> meets the <i>Cpp17MoveConstructible</i>, 
<i>Cpp17MoveAssignable</i>, and <i>Cpp17Swappable</i> (16.4.4.3 <a href="https://wg21.link/swappable.requirements">[swappable.requirements]</a>) requirements.</ins>
<p/>
-96- <i>Effects:</i> Inserts copies of elements in <code>rg</code> before <code>begin()</code>. 
Each iterator in the range <code>rg</code> is dereferenced exactly once.
<p/>
[<i>Note 3</i>: The order of elements in <code>rg</code> is not reversed. &mdash; <i>end note</i>]
<p/>
-97- <i>Remarks:</i> Required for <code>deque</code>, <code>forward_list</code>, and <code>list</code>.
</p>
</blockquote>
</blockquote>
</li>

</ol>





</body>
</html>
