<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2580: Who is definitive: operator= or assign?</title>
<meta property="og:title" content="Issue 2580: Who is definitive: operator= or assign?">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2580.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#NAD">NAD</a> status.</em></p>
<h3 id="2580"><a href="lwg-closed.html#2580">2580</a>. Who is definitive: <code>operator=</code> or <code>assign</code>?</h3>
<p><b>Section:</b> 27.4.3.3 <a href="https://wg21.link/string.cons">[string.cons]</a>, 27.4.3.7.3 <a href="https://wg21.link/string.assign">[string.assign]</a>, 28.6.7.3 <a href="https://wg21.link/re.regex.assign">[re.regex.assign]</a> <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> Marshall Clow <b>Opened:</b> 2016-01-05 <b>Last modified:</b> 2016-11-12</p>
<p><b>Priority: </b>4
</p>
<p><b>View all other</b> <a href="lwg-index.html#string.cons">issues</a> in [string.cons].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>
<p>
There are two "containers" in the standard who have member functions named <code>assign</code> that take parameters of the 
type of the container (as opposed to iterators, pointers, what have you).
<p/>
In <code>string</code>'s case, we define <code>assign</code> in terms of <code>operator=</code>.
In <code>regex</code>'s case, we define <code>operator=</code> in terms of <code>assign</code>.
<p/>
We should pick a style and use use it.
<p/>
In 27.4.3.3 <a href="https://wg21.link/string.cons">[string.cons]</a>, we have:
</p>
<blockquote>
<pre>
basic_string&amp; operator=(const basic_string&amp; str);
</pre>
<blockquote>
<p>
-17- <i>Effects</i>: If <code>*this</code> and <code>str</code> are not the same object, modifies <code>*this</code> as shown in Table 70. 
<p/>
-18- If <code>*this</code> and <code>str</code> are the same object, the member has no effect.
<p/>
-19- <i>Returns</i>: <code>*this</code>
</p>
</blockquote>
<pre>
basic_string&amp; operator=(basic_string&amp;&amp; str)
  noexcept(allocator_traits&lt;Allocator&gt;::propagate_on_container_move_assignment::value || 
           allocator_traits&lt;Allocator&gt;::is_always_equal::value);
</pre>
<blockquote>
<p>
-20- <i>Effects</i>: Move assigns as a sequence container (23.2), except that iterators, pointers and references may be invalidated.
<p/>
-21- <i>Returns</i>: <code>*this</code>
</p>
</blockquote>
</blockquote>
<p>
In 27.4.3.7.3 <a href="https://wg21.link/string.assign">[string.assign]</a>, we have:
</p>
<blockquote>
<pre>
basic_string&amp; assign(const basic_string&amp; str);
</pre>
<blockquote>
<p>
-1- <i>Effects</i>: Equivalent to <code>assign(str, 0, npos)</code>. 
<p/>
-2- <i>Returns</i>: <code>*this</code>.
</p>
</blockquote>
<pre>
basic_string&amp; assign(basic_string&amp;&amp; str) 
  noexcept(allocator_traits&lt;Allocator&gt;::propagate_on_container_move_assignment::value ||
           allocator_traits&lt;Allocator&gt;::is_always_equal::value);
</pre>
<blockquote>
<p>
-2- <i>Effects</i>: Equivalent to <code>*this = std::move(str)</code>.
<p/>
-3- <i>Returns</i>: <code>*this</code>.
</p>
</blockquote>
</blockquote>
<p>
Marshall says: There is another issue <a href="lwg-defects.html#2579" title="Inconsistency wrt Allocators in basic_string assignment vs. basic_string::assign (Status: C++17)">2579</a><sup><a href="https://cplusplus.github.io/LWG/issue2579" title="Latest snapshot">(i)</a></sup> here, to change /1 to be similar to /2.
<p/>
In 28.6.7.3 <a href="https://wg21.link/re.regex.assign">[re.regex.assign]</a>, we have:
</p>
<blockquote>
<pre>
basic_regex&amp; operator=(const basic_regex&amp; e);
</pre>
<blockquote>
<p>
-1- <i>Effects</i>: returns <code>assign(e)</code>.
</p>
</blockquote>
<pre>
basic_regex&amp; operator=(basic_regex&amp;&amp; e) noexcept;
</pre>
<blockquote>
<p>
-2- <i>Effects</i>: returns <code>assign(std::move(e))</code>.
</p>
</blockquote>
</blockquote>
<p>
<em>and</em>
</p> 
<blockquote>
<pre>
basic_regex&amp; assign(const basic_regex&amp; that);
</pre>
<blockquote>
<p>
-7- <i>Effects</i>: copies <code>that</code> into <code>*this</code> and returns <code>*this</code>.
<p/>
-8- <i>Postconditions</i>: <code>flags()</code> and <code>mark_count()</code> return <code>that.flags()</code> and 
<code>that.mark_count()</code>, respectively.
</p>
</blockquote>
<pre>
basic_regex&amp; assign(basic_regex&amp;&amp; that) noexcept;
</pre>
<blockquote>
<p>
-9- <i>Effects</i>: move assigns from <code>that</code> into <code>*this</code> and returns <code>*this</code>.
<p/>
-10- <i>Postconditions</i>: <code>flags()</code> and <code>mark_count()</code> return the values that <code>that.flags()</code> and 
<code>that.mark_count()</code>, respectively, had before assignment. <code>that</code> is in a valid state with unspecified value.
</p>
</blockquote>
</blockquote>

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

<p>
Marshall to see if this can be dealt with editorially. Change Regex so that assign is in terms of op=
</p>

<p><i>[2016-02]</i></p>

<p>
Changed <code>basic_regex</code> to match <code>string</code> as an editorial change. Closing as NAD
</p>


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





</body>
</html>
