<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2209: assign() overspecified for sequence containers</title>
<meta property="og:title" content="Issue 2209: assign() overspecified for sequence containers">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2209.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++14">C++14</a> status.</em></p>
<h3 id="2209"><a href="lwg-defects.html#2209">2209</a>. <code>assign()</code> overspecified for sequence containers</h3>
<p><b>Section:</b> 23.3 <a href="https://wg21.link/sequences">[sequences]</a> <b>Status:</b> <a href="lwg-active.html#C++14">C++14</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2012-10-31 <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#sequences">issues</a> in [sequences].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++14">C++14</a> status.</p>
<p><b>Discussion:</b></p>

<p>
DR <a href="lwg-defects.html#704" title="MoveAssignable requirement for container value type overly strict (Status: C++11)">704</a><sup><a href="https://cplusplus.github.io/LWG/issue704" title="Latest snapshot">(i)</a></sup> ensures allocator-aware containers can reuse existing
elements during copy/move assignment, and sequence containers can do
the same for <code>assign()</code>.
<p/>
But apart from <code>std::list</code> (which was changed by DR <a href="lwg-defects.html#320" title="list::assign overspecified (Status: CD1)">320</a><sup><a href="https://cplusplus.github.io/LWG/issue320" title="Latest snapshot">(i)</a></sup>) the sequence
containers define the Effects of <code>assign()</code> in terms of <code>clear()</code> followed
by <code>insert</code>.  A user-defined allocator can easily tell whether all old
elements are cleared and then new elements inserted or whether existing elements are assigned 
to, so those Effects clauses cannot be ignored via the as-if rule.
<p/>
The descriptions of the <code>assign()</code> members for <code>deque</code>, <code>forward_list</code> and
<code>vector</code> should be removed.  Their intended effects are entirely described by the 
sequence container requirements table, and the specific definitions of them are worse than 
redundant, they're contradictory (if the operations are defined in terms of <code>erase</code> and
<code>insert</code> then there's no need for elements to be assignable.)  The descriptions of 
<code>assign()</code> for <code>list</code> are correct but redundant, so should be removed too.
</p>

<p><i>[2013-03-15 Issues Teleconference]</i></p>

<p>
Moved to Tentatively Ready.
</p>

<p><i>[2013-04-20 Bristol]</i></p>




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

<ol>
<li><p>Edit 23.3.5.2 <a href="https://wg21.link/deque.cons">[deque.cons]</a> to remove everything after paragraph 10:</p>

<blockquote>
<pre>
<del>template &lt;class InputIterator&gt;
void assign(InputIterator first, InputIterator last);</del>
</pre>
<blockquote>
<p>
<del>-11- <i>Effects</i>:</del>
</p>
<blockquote><pre>
<del>erase(begin(), end());
insert(begin(), first, last);</del>
</pre></blockquote>
</blockquote>

<pre>
<del>void assign(size_type n, const T&amp; t);</del>
</pre>
<blockquote>
<p>
<del>-12- <i>Effects</i>:</del>
</p>
<blockquote><pre>
<del>erase(begin(), end());
insert(begin(), n, t);</del>
</pre></blockquote>
</blockquote>
</blockquote>

</li>

<li><p>Edit  [forwardlist.cons] to remove everything after paragraph 10:</p>

<blockquote>
<pre>
<del>template &lt;class InputIterator&gt;
void assign(InputIterator first, InputIterator last);</del>
</pre>
<blockquote>
<p>
<del>-11- <i>Effects</i>: <code>clear(); insert_after(before_begin(), first, last);</code></del>
</p>
</blockquote>

<pre>
<del>void assign(size_type n, const T&amp; t);</del>
</pre>
<blockquote>
<p>
<del>-12- <i>Effects</i>: <code>clear(); insert_after(before_begin(), n, t);</code></del>
</p>
</blockquote>
</blockquote>

</li>

<li><p>Edit 23.3.11.2 <a href="https://wg21.link/list.cons">[list.cons]</a> to remove everything after paragraph 10:</p>

<blockquote>
<pre>
<del>template &lt;class InputIterator&gt;
void assign(InputIterator first, InputIterator last);</del>
</pre>
<blockquote>
<p>
<del>-11- <i>Effects</i>: Replaces the contents of the list with the range <code>[first, last)</code>.</del>
</p>
</blockquote>

<pre>
<del>void assign(size_type n, const T&amp; t);</del>
</pre>
<blockquote>
<p>
<del>-12- <i>Effects</i>: Replaces the contents of the list with <code>n</code> copies of <code>t</code>.</del>
</p>
</blockquote>
</blockquote>

</li>

<li><p>Edit 23.3.13.2 <a href="https://wg21.link/vector.cons">[vector.cons]</a> to remove everything after paragraph 10:</p>

<blockquote>
<pre>
<del>template &lt;class InputIterator&gt;
void assign(InputIterator first, InputIterator last);</del>
</pre>
<blockquote>
<p>
<del>-11- <i>Effects</i>:</del>
</p>
<blockquote><pre>
<del>erase(begin(), end());
insert(begin(), first, last);</del>
</pre></blockquote>
</blockquote>

<pre>
<del>void assign(size_type n, const T&amp; t);</del>
</pre>
<blockquote>
<p>
<del>-12- <i>Effects</i>:</del>
</p>
<blockquote><pre>
<del>erase(begin(), end());
insert(begin(), n, t);</del>
</pre></blockquote>
</blockquote>
</blockquote>

</li>

</ol>






</body>
</html>
