<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2071: std::valarray move-assignment</title>
<meta property="og:title" content="Issue 2071: std::valarray move-assignment">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2071.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="2071"><a href="lwg-defects.html#2071">2071</a>. <code>std::valarray</code> move-assignment</h3>
<p><b>Section:</b> 29.6.2.3 <a href="https://wg21.link/valarray.assign">[valarray.assign]</a> <b>Status:</b> <a href="lwg-active.html#C++14">C++14</a>
 <b>Submitter:</b> Paolo Carlini <b>Opened:</b> 2011-05-05 <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#valarray.assign">issues</a> in [valarray.assign].</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>
Yesterday I noticed that the language we have in the FDIS about <code>std::valarray</code> move assignment 
is inconsistent with the resolution of LWG 675. Indeed, we guarantee constant complexity (vs linear 
complexity). We also want it to be noexcept, that is more subtle, but again it's at variance with all 
the containers.
<p/>
Also, even if we suppose that LWG <a href="lwg-defects.html#675" title="Move assignment of containers (Status: CD1)">675</a><sup><a href="https://cplusplus.github.io/LWG/issue675" title="Latest snapshot">(i)</a></sup> applies only to the containers proper, I don't think the current 
"as if by calling resize(v.size())" is internally consistent with the noexcept requirement.
<p/>
So, what do we really want for <code>std::valarray</code>? Shall we maybe just strike or fix the as-if, consider it 
some sort of pasto from the copy-assignment text, thus keep the noexcept and constant complexity requirements 
(essentially the whole operation would boild down to a swap of POD data members). Or LWG <a href="lwg-defects.html#675" title="Move assignment of containers (Status: CD1)">675</a><sup><a href="https://cplusplus.github.io/LWG/issue675" title="Latest snapshot">(i)</a></sup> should be 
explicitly extended to <code>std::valarray</code> too? In that case both noexcept and constant complexity 
would go, I think, and the operation would boil down to the moral equivalent of <code>clear()</code> (which 
doesn't really exist in this case) + <code>swap</code>?
</p>

<p>
Howard: I agree the current wording is incorrect.  The complexity should be linear in <code>size()</code> (not 
<code>v.size()</code>) because the first thing this operator needs to do is <code>resize(0)</code> (or <code>clear()</code> 
as you put it).
<p/>
I think we can keep the <code>noexcept</code>.
<p/>
As for proper wording, here's a first suggestion:
</p><blockquote><p>
<i>Effects</i>: <code>*this</code> obtains the value of <code>v</code>. The value of <code>v</code> after the assignment 
is not specified.
<p/>
<i>Complexity</i>: linear.
</p></blockquote><p>
</p>

<p>
See also reflector discussion starting with c++std-lib-30690.
</p>

<p><i>[2012, Kona]</i></p>

<p>
Move to Ready.
</p>
<p>
Some discussion on the types supported by <code>valarray</code> concludes that the wording is
trying to say something similar to the core wording for trivial types, but significantly
predates it, and does allow for types with non-trivial destructors.  Howard notes that
the only reason for linear complexity, rather than constant, is to support types with
non-trivial destructors.
</p>
<p>
AJM suggests replacing the word 'value' with 'state', but straw poll prefers moving
forward with the current wording, 5 to 2.
</p>

<p><i>[2012, Portland: applied to WP]</i></p>




<p id="res-2071"><b>Proposed resolution:</b></p>
<p>This wording is relative to the FDIS.</p>

<p>In 29.6.2.3 <a href="https://wg21.link/valarray.assign">[valarray.assign]</a> update as follows:</p>

<blockquote><pre>
valarray&lt;T&gt;&amp; operator=(valarray&lt;T&gt;&amp;&amp; v) noexcept;
</pre><blockquote><p>
3 <i>Effects</i>: <code>*this</code> obtains the value of <code>v</code>. <del>If the length of <code>v</code> 
is not equal to the length of <code>*this</code>, resizes <code>*this</code> to make the two arrays the 
same length, as if by calling <code>resize(v.size())</code>, before performing the assignment.</del><ins>The 
value of <code>v</code> after the assignment is not specified.</ins>
<p/>
4 <i>Complexity</i>: <del>Constant</del><ins>Linear</ins>.
</p></blockquote></blockquote>






</body>
</html>
