<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 621: non-const copy assignment operators of helper arrays</title>
<meta property="og:title" content="Issue 621: non-const copy assignment operators of helper arrays">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue621.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#CD1">CD1</a> status.</em></p>
<h3 id="621"><a href="lwg-defects.html#621">621</a>. non-const copy assignment operators of helper arrays</h3>
<p><b>Section:</b> 29.6 <a href="https://wg21.link/numarray">[numarray]</a> <b>Status:</b> <a href="lwg-active.html#CD1">CD1</a>
 <b>Submitter:</b> Martin Sebor <b>Opened:</b> 2007-01-20 <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#numarray">issues</a> in [numarray].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
        <p>

The computed and  "fill" assignment operators of <code>valarray</code>
helper     array     class    templates     (<code>slice_array</code>,
<code>gslice_array</code>,         <code>mask_array</code>,        and
<code>indirect_array</code>) are const  member functions of each class
template     (the     latter    by     the     resolution    of  <a href="lwg-defects.html#123" title="Should valarray helper arrays fill functions be const? (Status: CD1)">123</a><sup><a href="https://cplusplus.github.io/LWG/issue123" title="Latest snapshot">(i)</a></sup>
since  they have reference  semantics and thus do  not affect
the state of  the object on which they are  called.  However, the copy
assignment  operators  of  these  class  templates,  which  also  have
reference semantics,  are non-const.   The absence of  constness opens
the door to speculation about whether they really are intended to have
reference semantics (existing implementations vary widely).

        </p>

<p>
Pre-Kona, Martin adds:
</p>

<p>
I realized that adding the const qualifier to the
functions as I suggested would break the const correctness of the
classes. A few possible solutions come to mind:
</p>

<ol>
<li>Add the const qualifier to the return types of these functions.</li>
<li>Change the return type of all the functions to void to match
the signatures of all the other assignment operators these classes
define.</li>
<li>Prohibit the copy assignment of these classes by declaring the
copy assignment operators private (as is done and documented by
some implementations).</li>
</ol>



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

Declare  the  copy  assignment  operators  of all  four  helper  array
class templates const.

        </p>
        <p>

Specifically,  make the following edits:

        </p>
        <p>

Change     the    signature     in     29.6.5 <a href="https://wg21.link/template.slice.array">[template.slice.array]</a>    and
29.6.5.2 <a href="https://wg21.link/slice.arr.assign">[slice.arr.assign]</a> as follows:

        </p>
        <blockquote><pre>

<code><ins>const</ins> slice_array&amp; operator= (const slice_array&amp;)<ins> const</ins>;</code>

        </pre></blockquote>
        <p>

Change     the     signature     in    29.6.7 <a href="https://wg21.link/template.gslice.array">[template.gslice.array]</a>     and
29.6.7.2 <a href="https://wg21.link/gslice.array.assign">[gslice.array.assign]</a> as follows:

        </p>
        <blockquote><pre>

<code><ins>const</ins> gslice_array&amp; operator= (const gslice_array&amp;)<ins> const</ins>;</code>

        </pre></blockquote>
        <p>

Change the  signature in 29.6.8 <a href="https://wg21.link/template.mask.array">[template.mask.array]</a>  and 29.6.8.2 <a href="https://wg21.link/mask.array.assign">[mask.array.assign]</a> as
follows:

        </p>
        <blockquote><pre>

<code><ins>const</ins> mask_array&amp; operator= (const mask_array&amp;)<ins> const</ins>;</code>

        </pre></blockquote>
        <p>

Change     the     signature     in    29.6.9 <a href="https://wg21.link/template.indirect.array">[template.indirect.array]</a> and
29.6.9.2 <a href="https://wg21.link/indirect.array.assign">[indirect.array.assign]</a> as follows:

        </p>
        <blockquote><pre>

<code><ins>const</ins> indirect_array&amp; operator= (const indirect_array&amp;)<ins> const</ins>;</code>

        </pre></blockquote>


<p><i>[
Kona (2007) Added const qualification to the return types and set to Ready.
]</i></p>





</body>
</html>
