<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 900: Stream move-assignment</title>
<meta property="og:title" content="Issue 900: Stream move-assignment">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue900.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="900"><a href="lwg-defects.html#900">900</a>. Stream move-assignment</h3>
<p><b>Section:</b> 31.10.4 <a href="https://wg21.link/ifstream">[ifstream]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Niels Dekker <b>Opened:</b> 2008-09-20 <b>Last modified:</b> 2023-02-07</p>
<p><b>Priority: </b>Not Prioritized
</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>
It appears that we have an issue similar to issue <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> regarding the move-assignment of
stream types. For example, when assigning to an <code>std::ifstream</code>, <code>ifstream1</code>, it 
seems preferable to close the file originally held by <code>ifstream1</code>:
</p>

<blockquote><pre>
ifstream1 = std::move(ifstream2); 
</pre></blockquote>

<p>
The current Draft
(<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2723.pdf">N2723</a>)
specifies that the move-assignment of stream types like <code>ifstream</code> has the 
same effect as a swap:
</p>

<blockquote>
<p>
Assign and swap  [ifstream.assign]
</p>
<pre>
basic_ifstream&amp; operator=(basic_ifstream&amp;&amp; rhs); 
</pre>
<blockquote><p>
<i>Effects:</i> <code>swap(rhs)</code>.
</p></blockquote>
</blockquote>

<p><i>[
Batavia (2009-05):
]</i></p>

<blockquote>
<p>
Howard agrees with the analysis and the direction proposed.
</p>
<p>
Move to Open pending specific wording to be supplied by Howard.
</p>
</blockquote>

<p><i>[
2009-07 Frankfurt:
]</i></p>


<blockquote><p>
Howard is going to write wording.
</p></blockquote>

<p><i>[
2009-07-26 Howard provided wording.
]</i></p>


<p><i>[
2009-09-13 Niels adds:
]</i></p>


<blockquote><p>
Note: The proposed change of 31.10.3.3 <a href="https://wg21.link/filebuf.assign">[filebuf.assign]</a> p1 depends on the
resolution of LWG <a href="lwg-defects.html#1204" title="Global permission to move (Status: C++11)">1204</a><sup><a href="https://cplusplus.github.io/LWG/issue1204" title="Latest snapshot">(i)</a></sup>, which allows implementations to assume that
<code>*this</code> and <code>rhs</code> refer to different objects.
</p></blockquote>

<p><i>[
2009 Santa Cruz:
]</i></p>


<blockquote><p>
Leave as Open.  Too closely related to <a href="lwg-defects.html#911" title="I&#47;O streams and move&#47;swap semantic (Status: C++11)">911</a><sup><a href="https://cplusplus.github.io/LWG/issue911" title="Latest snapshot">(i)</a></sup> to move on at this time.
</p></blockquote>

<p><i>[
2010 Pittsburgh:
]</i></p>


<blockquote><p>
Moved to Ready for Pittsburgh.
</p></blockquote>



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

<p>
Change 31.8.2.3 <a href="https://wg21.link/stringbuf.assign">[stringbuf.assign]</a>/1:
</p>

<blockquote><pre>
basic_stringbuf&amp; operator=(basic_stringbuf&amp;&amp; rhs);
</pre>
<blockquote><p>
-1- <i>Effects:</i> <del><code>swap(rhs)</code>.</del>
<ins>After the move assignment <code>*this</code> reflects the same observable
state it would have if it had been move constructed from <code>rhs</code>
(31.8.2.2 <a href="https://wg21.link/stringbuf.cons">[stringbuf.cons]</a>).
</ins>
</p></blockquote>
</blockquote>

<p>
Change  [istringstream.assign]/1:
</p>

<blockquote><pre>
basic_istringstream&amp; operator=(basic_istringstream&amp;&amp; rhs);
</pre>
<blockquote><p>
-1- <i>Effects:</i> <del><code>swap(rhs)</code>.</del>
<ins>Move assigns the base and members of <code>*this</code> with the respective
base and members of <code>rhs</code>.
</ins>
</p></blockquote>
</blockquote>

<p>
Change  [ostringstream.assign]/1:
</p>

<blockquote><pre>
basic_ostringstream&amp; operator=(basic_ostringstream&amp;&amp; rhs);
</pre>
<blockquote><p>
-1- <i>Effects:</i> <del><code>swap(rhs)</code>.</del>
<ins>Move assigns the base and members of <code>*this</code> with the respective
base and members of <code>rhs</code>.
</ins>
</p></blockquote>
</blockquote>

<p>
Change  [stringstream.assign]/1:
</p>

<blockquote><pre>
basic_stringstream&amp; operator=(basic_stringstream&amp;&amp; rhs);
</pre>
<blockquote><p>
-1- <i>Effects:</i> <del><code>swap(rhs)</code>.</del>
<ins>Move assigns the base and members of <code>*this</code> with the respective
base and members of <code>rhs</code>.
</ins>
</p></blockquote>
</blockquote>

<p>
Change 31.10.3.3 <a href="https://wg21.link/filebuf.assign">[filebuf.assign]</a>/1:
</p>

<blockquote><pre>
basic_filebuf&amp; operator=(basic_filebuf&amp;&amp; rhs);
</pre>
<blockquote><p>
-1- <i>Effects:</i> <del><code>swap(rhs)</code>.</del>
<ins>Begins by calling <code>this-&gt;close()</code>.
After the move assignment <code>*this</code> reflects the same observable
state it would have if it had been move constructed from <code>rhs</code>
(31.10.3.2 <a href="https://wg21.link/filebuf.cons">[filebuf.cons]</a>).
</ins>
</p></blockquote>
</blockquote>

<p>
Change  [ifstream.assign]/1:
</p>

<blockquote><pre>
basic_ifstream&amp; operator=(basic_ifstream&amp;&amp; rhs);
</pre>
<blockquote><p>
-1- <i>Effects:</i> <del><code>swap(rhs)</code>.</del>
<ins>Move assigns the base and members of <code>*this</code> with the respective
base and members of <code>rhs</code>.</ins>
</p></blockquote>
</blockquote>

<p>
Change  [ofstream.assign]/1:
</p>

<blockquote><pre>
basic_ofstream&amp; operator=(basic_ofstream&amp;&amp; rhs);
</pre>
<blockquote><p>
-1- <i>Effects:</i> <del><code>swap(rhs)</code>.</del>
<ins>Move assigns the base and members of <code>*this</code> with the respective
base and members of <code>rhs</code>.</ins>
</p></blockquote>
</blockquote>

<p>
Change  [fstream.assign]/1:
</p>

<blockquote><pre>
basic_fstream&amp; operator=(basic_fstream&amp;&amp; rhs);
</pre>
<blockquote><p>
-1- <i>Effects:</i> <del><code>swap(rhs)</code>.</del>
<ins>Move assigns the base and members of <code>*this</code> with the respective
base and members of <code>rhs</code>.</ins>
</p></blockquote>
</blockquote>






</body>
</html>
