<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2585: forward_list::resize(size_type, const value_type&amp;) effects incorrect</title>
<meta property="og:title" content="Issue 2585: forward_list::resize(size_type, const value_type&amp;) effects incorrect">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2585.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++17">C++17</a> status.</em></p>
<h3 id="2585"><a href="lwg-defects.html#2585">2585</a>. <code>forward_list::resize(size_type, const value_type&amp;)</code> effects incorrect</h3>
<p><b>Section:</b> 23.3.7.5 <a href="https://wg21.link/forward.list.modifiers">[forward.list.modifiers]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2016-01-14 <b>Last modified:</b> 2023-02-07</p>
<p><b>Priority: </b>0
</p>
<p><b>View all other</b> <a href="lwg-index.html#forward.list.modifiers">issues</a> in [forward.list.modifiers].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
 [forwardlist.modifiers]/29 says that the effects of <code>forward_list::resize(size_type sz, const value_type&amp; c)</code> 
are:
</p>
<blockquote class="note"><p>
<i>Effects</i>: If <code>sz &lt; distance(begin(), end())</code>, erases the last <code>distance(begin(), end()) - sz</code> elements
from the list. Otherwise, inserts <code>sz - distance(begin(), end())</code> elements at the end of
the list such that each new element, <code>e</code>, is initialized by a method equivalent to calling 
<code>allocator_traits&lt;allocator_type&gt;::construct(get_allocator(), std::addressof(e), c)</code>.
</p></blockquote>
<p>
In light of LWG <a href="lwg-defects.html#2218" title="Unclear how containers use allocator_traits::construct() (Status: C++17)">2218</a><sup><a href="https://cplusplus.github.io/LWG/issue2218" title="Latest snapshot">(i)</a></sup>, the use of <code>allocator_traits&lt;allocator_type&gt;::construct</code> is incorrect, 
as a rebound allocator may be used. There's no need to repeat this information, in any event &mdash; no other specification 
of <code>resize()</code> does it.
</p>

<p><i>[2016-02, Issues Telecon]</i></p>

<p>
P0; move to Tentatively Ready.
</p>

<p><i>[2016-02-11, Alisdair requests reopening]</i></p>

<p>
I believe the standard is correct as written, and that by removing the clear direction
to make the copy with uses-allocator-construction, we open ourselves to disputing
this very point again at some point in the future.
<p/>
The issue seems to be complaining that a rebound allocator may be used instead of
the allocator returned by <code>get_allocator()</code> call, and nailing us down to exactly which
instantiation of <code>allocator_traits</code> is used. Given the requirements on allocators being
constructible from within the same template "family" though, and specifically that
copies compare equal and can allocate/deallocate on each other's behalf, this should
clearly fall under existing as-if freedom. The construct call is even more clear, as
there is no requirement that the allocator to construct be of a kind that can allocate
the specific type being constructed &mdash; a freedom granted precisely so this kind of code
can be written, and be correct, regardless of internal node type of any container and
the actual rebound allocator used internally.
<p/>
I think the new wording is less clear than the current wording, and would prefer to
resolve as NAD.
</p>


<p id="res-2585"><b>Proposed resolution:</b></p>
<p>
This wording is relative to N4567.
</p>

<ol>
<li><p>Edit  [forwardlist.modifiers]/29 as indicated:</p>
<blockquote class="note">
<p>
[<i>Drafting note</i>: "copies of <code>c</code>" is the phrase used by <code>vector::resize</code> and <code>deque::resize</code>.]
</p>
</blockquote>

<blockquote>
<pre>
void resize(size_type sz, const value_type&amp; c);
</pre>
<blockquote>
<p>
-29- <i>Effects</i>: If <code>sz &lt; distance(begin(), end())</code>, erases the last <code>distance(begin(), end()) - sz</code> elements
from the list. Otherwise, inserts <code>sz - distance(begin(), end())</code> <del>elements</del><ins>copies of <code>c</code></ins> at 
the end of the list <del>such that each new element, <code>e</code>, is initialized by a method equivalent to calling 
<code>allocator_traits&lt;allocator_type&gt;::construct(get_allocator(), std::addressof(e), c)</code></del>.
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
