<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 430: valarray subset operations</title>
<meta property="og:title" content="Issue 430: valarray subset operations">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue430.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="430"><a href="lwg-defects.html#430">430</a>. <code>valarray</code> subset operations</h3>
<p><b>Section:</b> 29.6.2.5 <a href="https://wg21.link/valarray.sub">[valarray.sub]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Martin Sebor <b>Opened:</b> 2003-09-18 <b>Last modified:</b> 2016-01-28</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>
The standard fails to specify the behavior of valarray::operator[](slice)
and other valarray subset operations when they are passed an "invalid"
slice object, i.e., either a slice that doesn't make sense at all (e.g.,
slice (0, 1, 0) or one that doesn't specify a valid subset of the valarray
object (e.g., slice (2, 1, 1) for a valarray of size 1).
</p>
<p><i>[Kona: the LWG believes that invalid slices should invoke
  undefined behavior.  Valarrays are supposed to be designed for high
  performance, so we don't want to require specific checking.  We
  need wording to express this decision.]</i></p>


<p><i>[
Bellevue:
]</i></p>


<blockquote><p>
Please note that the standard also fails to specify the behavior of
slice_array and gslice_array in the valid case. Bill Plauger will
endeavor to provide revised wording for <code>slice_array</code> and <code>gslice_array</code>.
</p></blockquote>

<p><i>[
post-Bellevue:  Bill provided wording.
]</i></p>


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


<blockquote>
<p>
Move to Ready.
</p>
</blockquote>

<p><i>[
2009-11-04 Pete opens:
]</i></p>


<blockquote><p>
The resolution to LWG issue <a href="lwg-defects.html#430" title="valarray subset operations (Status: C++11)">430</a><sup><a href="https://cplusplus.github.io/LWG/issue430" title="Latest snapshot">(i)</a></sup> has not been applied &mdash; there have been
changes to the underlying text, and the resolution needs to be reworked.
</p></blockquote>

<p><i>[
2010-03-09 Matt updated wording.
]</i></p>


<p><i>[
2010 Pittsburgh: Moved to Ready for Pittsburgh.
]</i></p>




<p id="res-430"><b>Proposed resolution:</b></p>
<p>
Replace 29.6.2.5 <a href="https://wg21.link/valarray.sub">[valarray.sub]</a>, with the following:
</p>

<blockquote>
<p>
The member operator is overloaded to provide several ways to select
sequences of elements from among those controlled by <code>*this</code>.
Each of these operations returns a subset of the array.  The
const-qualified versions return this subset as a new <code>valarray</code>. The
non-const versions return a class template object which has reference
semantics to the original array, working in conjunction with various
overloads of <code>operator=</code> (and other assigning operators) to allow
selective replacement (slicing) of the controlled sequence. In each case
the selected element(s) must exist.
</p>

<pre>
valarray&lt;T&gt; operator[](slice slicearr) const; 
</pre>

<blockquote>
<p>
This function returns an object of class <code>valarray&lt;T&gt;</code>
containing those elements of the controlled sequence designated by
<code>slicearr</code>. [<i>Example:</i>
</p>

<blockquote><pre>
valarray&lt;char&gt; v0("abcdefghijklmnop", 16); 
valarray&lt;char&gt; v1("ABCDE", 5); 
v0[slice(2, 5, 3)] = v1; 
// v0 == valarray&lt;char&gt;("abAdeBghCjkDmnEp", 16)
</pre></blockquote>
<p>
<i>end example</i>]
</p>
</blockquote>
 
<pre>
valarray&lt;T&gt; operator[](slice slicearr); 
</pre>

<blockquote>
<p>
This function selects those elements of the controlled sequence
designated by <code>slicearr</code>.  [<i>Example</i>:
</p>

<blockquote><pre>
valarray&lt;char&gt; v0("abcdefghijklmnop", 16); 
valarray&lt;char&gt; v1("ABCDE", 5); 
v0[slice(2, 5, 3)] = v1; 
// v0 == valarray&lt;char&gt;("abAdeBghCjkDmnEp", 16)
</pre></blockquote>
<p>
<i>end example</i>]
</p>
</blockquote>
 
<pre>
valarray&lt;T&gt; operator[](const gslice&amp; gslicearr) const; 
</pre>

<blockquote>
<p>
This function returns an object of class <code>valarray&lt;T&gt;</code>
containing those elements of the controlled sequence designated by
<code>gslicearr</code>. [<i>Example:</i>
</p>

<blockquote><pre>
valarray&lt;char&gt; v0("abcdefghijklmnop", 16); 
const size_t lv[] = {2, 3}; 
const size_t dv[] = {7, 2}; 
const valarray&lt;size_t&gt; len(lv, 2), str(dv, 2); 
// v0[gslice(3, len, str)] returns 
// valarray&lt;char&gt;("dfhkmo", 6)
</pre></blockquote>
<p>
<i>end example</i>]
</p>
</blockquote>
 
<pre>
gslice_array&lt;T&gt; operator[](const gslice&amp; gslicearr); 
</pre>

<blockquote>
<p>
This function selects those elements of the controlled sequence
designated by <code>gslicearr</code>.  [<i>Example:</i>
</p>

<blockquote><pre>
valarray&lt;char&gt; v0("abcdefghijklmnop", 16); 
valarray&lt;char&gt; v1("ABCDEF", 6); 
const size_t lv[] = {2, 3}; 
const size_t dv[] = {7, 2}; 
const valarray&lt;size_t&gt; len(lv, 2), str(dv, 2); 
v0[gslice(3, len, str)] = v1; 
// v0 == valarray&lt;char&gt;("abcAeBgCijDlEnFp", 16)
</pre></blockquote>
<p>
<i>end example</i>]
</p>
</blockquote>
 
<pre>
valarray&lt;T&gt; operator[](const valarray&lt;bool&gt;&amp; boolarr) const; 
</pre>

<blockquote>
<p>
This function returns an object of class <code>valarray&lt;T&gt;</code>
containing those elements of the controlled sequence designated by
<code>boolarr</code>. [<i>Example:</i>
</p>

<blockquote><pre>
valarray&lt;char&gt; v0("abcdefghijklmnop", 16); 
const bool vb[] = {false, false, true, true, false, true}; 
// v0[valarray&lt;bool&gt;(vb, 6)] returns 
// valarray&lt;char&gt;("cdf", 3)
</pre></blockquote>
<p>
<i>end example</i>] 
</p>
</blockquote>
 
<pre>
mask_array&lt;T&gt; operator[](const valarray&lt;bool&gt;&amp; boolarr); 
</pre>

<blockquote>
<p>
This function selects those elements of the controlled sequence
designated by <code>boolarr</code>. [<i>Example:</i>
</p>

<blockquote><pre>
valarray&lt;char&gt; v0("abcdefghijklmnop", 16); 
valarray&lt;char&gt; v1("ABC", 3); 
const bool vb[] = {false, false, true, true, false, true}; 
v0[valarray&lt;bool&gt;(vb, 6)] = v1; 
// v0 == valarray&lt;char&gt;("abABeCghijklmnop", 16)
</pre></blockquote>
<p>
<i>end example</i>]
</p>
</blockquote>
 
<pre>
valarray&lt;T&gt; operator[](const valarray&lt;size_t&gt;&amp; indarr) const; 
</pre>

<blockquote>
<p>
This function returns an object of class <code>valarray&lt;T&gt;</code>
containing those elements of the controlled sequence designated by
<code>indarr</code>. [<i>Example:</i>
</p>

<blockquote><pre>
valarray&lt;char&gt; v0("abcdefghijklmnop", 16); 
const size_t vi[] = {7, 5, 2, 3, 8}; 
// v0[valarray&lt;size_t&gt;(vi, 5)] returns 
// valarray&lt;char&gt;("hfcdi", 5)
</pre></blockquote>
<p>
<i>end example</i>] 
</p>
</blockquote>
 
<pre>
indirect_array&lt;T&gt; operator[](const valarray&lt;size_t&gt;&amp; indarr);
</pre>

<blockquote>
<p>
This function selects those elements of the controlled sequence
designated by <code>indarr</code>. [<i>Example:</i>
</p>

<blockquote><pre>
valarray&lt;char&gt; v0("abcdefghijklmnop", 16); 
valarray&lt;char&gt; v1("ABCDE", 5); 
const size_t vi[] = {7, 5, 2, 3, 8}; 
v0[valarray&lt;size_t&gt;(vi, 5)] = v1; 
// v0 == valarray&lt;char&gt;("abCDeBgAEjklmnop", 16)
</pre></blockquote>
<p>
<i>end example</i>]
</p>
</blockquote>

</blockquote>





</body>
</html>
