<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1340: Why does forward_list::resize take the object to be copied by value?</title>
<meta property="og:title" content="Issue 1340: Why does forward_list::resize take the object to be copied by value?">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1340.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="1340"><a href="lwg-defects.html#1340">1340</a>. Why does <code>forward_list::resize</code> take the object to be copied by value?</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++11">C++11</a>
 <b>Submitter:</b> James McNellis <b>Opened:</b> 2010-07-16 <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.modifiers">issues</a> in [forward.list.modifiers].</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>
In
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3092.pdf">N3092</a>
 [forwardlist.modifiers], the <code>resize()</code> member function is 
declared as:
</p>

<blockquote><pre>
void resize(size_type sz, value_type c); 
</pre></blockquote>

<p>
The other sequence containers (<code>list</code>, <code>deque</code>, and
<code>vector</code>) take <code>'c'</code> by const reference.
</p>

<p>
Is there a reason for this difference?  If not, then <code>resize()</code> should 
be declared as: 
</p>

<blockquote><pre>
void resize(size_type sz, const value_type&amp; c); 
</pre></blockquote>

<p>
The declaration would need to be changed both at its declaration in the class
definition at  [forwardlist]/3 and where its behavior is specified
at  [forwardlist.modifiers]/22.
</p>

<p>
This would make <code>forward_list</code> consistent with the CD1 issue <a href="lwg-defects.html#679" title="resize parameter by value (Status: CD1)">679</a><sup><a href="https://cplusplus.github.io/LWG/issue679" title="Latest snapshot">(i)</a></sup>.
</p>

<p><i>[
Post-Rapperswil
]</i></p>


<p>
Daniel changed the P&#47;R slightly, because one paragraph number has been changed since the issue
had been submitted. He also added a similar Requires element that exists in all other containers with
a <code>resize</code> member function. He deliberately did not touch the wrong usage of "default-constructed" because that
will be taken care of by LWG issue <a href="lwg-defects.html#868" title="Default construction and value-initialization (Status: C++11)">868</a><sup><a href="https://cplusplus.github.io/LWG/issue868" title="Latest snapshot">(i)</a></sup>.
</p>

<blockquote><p>
Moved to Tentatively Ready with revised wording after 5 positive votes on c++std-lib.
</p></blockquote>

<p><i>[
Adopted at 2010-11 Batavia
]</i></p>




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


<ol>
<li>Change [forwardlist]/3, class template <code>forward_list</code> synopsis, as indicated:
<blockquote><pre>
...
void resize(size_type sz);
void resize(size_type sz, <ins>const</ins> value_type<ins>&amp;</ins> c);
void clear();
...
</pre></blockquote>
</li>
<li>Change [forwardlist.modifiers]/27 as indicated: 
<blockquote><pre>	
void resize(size_type sz);
void resize(size_type sz, <ins>const</ins> value_type<ins>&amp;</ins> c);
</pre>
<blockquote><p>
27 <em>Effects</em>: 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. For the first 
signature the inserted elements are default constructed, and for the second signature they are copies of <code>c</code>.
<p/>
<ins>28 - <em>Requires</em>: <code>T</code> shall be <code>DefaultConstructible</code> for the first form and	it shall be <code>CopyConstructible</code> 
	for the second form.</ins>
</p></blockquote></blockquote>
</li>
</ol>






</body>
</html>
