<html>
<head>
<title>Rvalue Reference Recommendations for Chapter 26</title>
<style>
p {text-align:justify}
li {text-align:justify}
blockquote.note
{
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
}
ins {background-color:#FFFFA0}
del {background-color:#FFFFA0}
</style>
</head>

<body>

<address align=right>
Document number: N1861=05-0121<br>
<br>
<a href="mailto:hinnant@twcny.rr.com">Howard E. Hinnant</a><br>
2005-08-26
</address>
<hr>

<h1 align=center>Rvalue Reference Recommendations for Chapter 26</h1>

<h2>Contents</h2>

<ul>
<li><a href="#Introduction">Introduction</a></li>
<li>
<a href="#26.3 - Numeric arrays">26.3 - Numeric arrays</a>
	<ul>
	<li>
	<a href="#26.3.1 - Header &lt;valarray&gt; synopsis">26.3.1 - Header
<tt>&lt;valarray&gt;</tt> synopsis</a>
	</li>
	<li>
	<a href="#26.3.2 - Class template valarray">26.3.2 - Class template
<tt>valarray</tt></a>
		<ul>
		<li>
		<a href="#26.3.2.1 - valarray constructors">26.3.2.1 - <tt>valarray</tt>
constructors</a>
		</li>
		<li>
		<a href="#26.3.2.2 - valarray assignment">26.3.2.2 - <tt>valarray</tt>
assignment</a>
		</li>
		<li>
		<a href="#26.3.2.7 - valarray member functions">26.3.2.7 - <tt>valarray</tt>
member functions</a>
		</li>
		</ul>
	</li>
	<li>
	<a href="#26.3.3 - valarray non-member functions">26.3.3 - <tt>valarray</tt>
non-member functions</a>
		<ul>
		<li>
		<a href="#26.3.3.4 - valarray specialized algorithms">26.3.3.4 -
<tt>valarray</tt> specialized algorithms</a>
		</li>
		</ul> 	</li> 	</ul>
</li>
</ul>

<h2>Related papers</h2>

<p>
<a href="n1856.html">Rvalue Reference Recommendations for Chapter 20</a><br>
<a href="n1857.html">Rvalue Reference Recommendations for Chapter 21</a><br>
<a href="n1858.html">Rvalue Reference Recommendations for Chapter 23</a><br>
<a href="n1859.html">Rvalue Reference Recommendations for Chapter 24</a><br>
<a href="n1860.html">Rvalue Reference Recommendations for Chapter 25</a><br>
<a href="n1862.html">Rvalue Reference Recommendations for Chapter 27</a>
</p>

<h2><a name="Introduction"></a>Introduction</h2>

<p>
This paper recommends proposed wording with respect to the
<a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1690.html">rvalue
reference</a> for the
<a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1804.pdf">C++0X
working draft</a>.
This paper restricts its scope to Chapter 26 "Numerics library" for the purpose
of breaking the library work associated with the rvalue reference up into
manageable chunks. This paper largely follows the lead of
<a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1771.html">N1771:
Impact of the rvalue reference on the Standard Library</a>, but adds more detail
as appropriate.
</p>

<p>
With the exception of this introduction, all non-proposed wording will have a
background color and formatting that
</p>
<blockquote class="note">
looks like this, so that motivation and description is more easily distinguished
from proposed wording.
</blockquote>
<p>
In the proposed wording below, text to be inserted is formatted like
<ins>this</ins>, while wording to be deleted is formatted like <del>this</del>.
</p>

<p>
The proposed wording in this paper simply adds to the class template
<tt>valarray</tt>:
</p>

<ul>
<li>A move constructor.</li>
<li>A move assignment operator.</li>
<li>A member <tt>swap</tt>.</li>
<li>Non-member <tt>swap</tt>s.</li>
</ul>

<h2><a name="26.3 - Numeric arrays"></a>26.3 - Numeric arrays</h2>
<h3><a name="26.3.1 - Header &lt;valarray&gt; synopsis"></a>26.3.1 - Header <tt>&lt;valarray&gt;</tt> synopsis</h3>

<blockquote><pre>
  ...
  template&lt;class T&gt; class indirect_array;   //  an indirected array

  <ins>template&lt;T&gt; void swap(valarray&lt;T&gt;&amp;, valarray&lt;T&gt;&amp;);
  template&lt;T&gt; void swap(valarray&lt;T&gt;&amp;&amp;, valarray&lt;T&gt;&amp;);
  template&lt;T&gt; void swap(valarray&lt;T&gt;&amp;, valarray&lt;T&gt;&amp;&amp;);</ins>

  template&lt;class T&gt; valarray&lt;T&gt; operator*
    (const valarray&lt;T&gt;&amp;, const valarray&lt;T&gt;&amp;);
  ...
</pre></blockquote>

<h3><a name="26.3.2 - Class template valarray"></a>26.3.2 - Class template <tt>valarray</tt></h3>

<blockquote><pre>
namespace std {
  template&lt;class T&gt; class valarray {
  public:
    typedef T value_type;

    //  lib.valarray.cons construct/destroy:
    valarray();
    explicit valarray(size_t);
    valarray(const T&amp;, size_t);
    valarray(const T*, size_t);
    valarray(const valarray&amp;);
    <ins>valarray(valarray&amp;&amp;);</ins>
    valarray(const slice_array&lt;T&gt;&amp;);
    valarray(const gslice_array&lt;T&gt;&amp;);
    valarray(const mask_array&lt;T&gt;&amp;);
    valarray(const indirect_array&lt;T&gt;&amp;);
   ~valarray();

    //  lib.valarray.assign assignment:
    valarray<del>&lt;T&gt;</del>&amp; operator=(const valarray<del>&lt;T&gt;</del>&amp;);
    <ins>valarray&amp; operator=(valarray&amp;&amp;);</ins>
    valarray<del>&lt;T&gt;</del>&amp; operator=(const T&amp;);
    valarray<del>&lt;T&gt;</del>&amp; operator=(const slice_array&lt;T&gt;&amp;);
    valarray<del>&lt;T&gt;</del>&amp; operator=(const gslice_array&lt;T&gt;&amp;);
    valarray<del>&lt;T&gt;</del>&amp; operator=(const mask_array&lt;T&gt;&amp;);
    valarray<del>&lt;T&gt;</del>&amp; operator=(const indirect_array&lt;T&gt;&amp;);

    <ins>void swap(valarray&amp;&amp;);</ins>

    //  lib.valarray.access element access:
    T                 operator[](size_t) const;
    T&amp;                operator[](size_t);
    ...
</pre></blockquote>

<h4><a name="26.3.2.1 - valarray constructors"></a>26.3.2.1 - <tt>valarray</tt> constructors</h4>

<p>...</p>

<blockquote><pre>
valarray(const valarray&lt;T&gt;&amp;);
</pre></blockquote>

<p>
-5- The array created by this constructor has the same length as the argument
array. The elements are initialized with the values of the corresponding
elements of the argument array.*
</p>

<blockquote>
[<i>Footnote:</i> This copy constructor creates a distinct array rather than an
alias. Implementations in which arrays share storage are permitted, but they
shall implement a copy-on-reference mechanism to ensure that arrays are
conceptually distinct. <i>--- end footnote</i>]
</blockquote>

<blockquote><pre><ins>
valarray(valarray&amp;&amp; v);
</ins></pre></blockquote>

<p><ins>
-6- The array created by this constructor has the same length as the argument
array.  The elements are initialized with the values of the corresponding
elements of the argument array.  The value of <tt>v</tt> after the construction
is not specified.
</ins></p>

<p><ins>
-7- <b>Complexity:</b> Constant.
</ins></p>

<p><ins>
-8- <b>Throws:</b> Nothing.
</ins></p>

<p>...</p>

<h4><a name="26.3.2.2 - valarray assignment"></a>26.3.2.2 - <tt>valarray</tt> assignment</h4>

<blockquote><pre>
valarray&lt;T&gt;&amp; operator=(const valarray&lt;T&gt;&amp;);
</pre></blockquote>

<p>
-1- Each element of the <tt>*this</tt> array is assigned the value of the
corresponding element of the argument array. The resulting behavior is undefined
if the length of the argument array is not equal to the length of the
<tt>*this</tt> array.
</p>

<blockquote><pre><ins>
valarray&amp; operator=(valarray&amp;&amp; v);
</ins></pre></blockquote>

<p><ins>
-2- <b>Effects:</b> <tt>*this</tt> obtains the value of <tt>v</tt>.
 The value of <tt>v</tt> after the assignment is not specified.
</ins></p>

<p><ins>
-3- <b>Complexity:</b> Constant.
</ins></p>

<p><ins>
-4- <b>Throws:</b> Nothing.
</ins></p>

<h4><a name="26.3.2.7 - valarray member functions"></a>26.3.2.7 - <tt>valarray</tt> member functions</h4>

<blockquote><pre><ins>
void swap(valarray&amp;&amp; v);
</ins></pre></blockquote>

<p><ins>
-10- <b>Effects:</b> <tt>*this</tt> obtains the value of <tt>v</tt>.
 The value of <tt>v</tt> obtains the value of <tt>*this</tt>.
</ins></p>

<p><ins>
-11- <b>Complexity:</b> Constant.
</ins></p>

<p><ins>
-12- <b>Throws:</b> Nothing.
</ins></p>

<h3><a name="26.3.3 - valarray non-member functions"></a>26.3.3 - <tt>valarray</tt> non-member functions</h3>
<h4><a name="26.3.3.4 - valarray specialized algorithms"></a><ins>26.3.3.4 - <tt>valarray</tt> specialized algorithms</ins></h4>

<blockquote><pre><ins>
template&lt;T&gt; void swap(valarray&lt;T&gt;&amp; x, valarray&lt;T&gt;&amp; y);
template&lt;T&gt; void swap(valarray&lt;T&gt;&amp;&amp; x, valarray&lt;T&gt;&amp; y);
template&lt;T&gt; void swap(valarray&lt;T&gt;&amp; x, valarray&lt;T&gt;&amp;&amp; y);
</ins></pre></blockquote>

<p><ins>
-1- <b>Effects:</b> <tt>x.swap(y)</tt>.
</ins></p>
</body>
</html>
