Topic: Proposal: Copy elision in rvalue-ref-qualified member functions


Author: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Date: Sat, 4 Jan 2014 07:56:59 -0800 (PST)
Raw View
------=_Part_4858_26720673.1388851019403
Content-Type: text/plain; charset=ISO-8859-1



In the following cases it is natural to allow copy elision to take place:

class A
{
     double *v;
     std::size_t n;


public:
.. . .
        A operator+(A x) const &
        {
                for (std::size_t i = 0; i < n; i++)
                {
                        x.v[i] += v[i];
                }
                return x; // copy elision will take place here
        }

         A operator+(const A& x) && // rvalue-ref-qualified
         {
                 for (std::size_t i = 0; i < n; i++)
                 {
                         v[i] += x.v[i];
                 }
                 return std::move(*this); // At present, std::move is
required here in order to get the desired effect. But it seems that  return
*this; should be enough.
         }
.. . .
};

This proposal can be accessed through the following link:
*https://dl.dropboxusercontent.com/u/35715999/copy_elision_for_r_value_qualified_members.htm*<https://dl.dropboxusercontent.com/u/35715999/copy_elision_for_r_value_qualified_members.htm>


--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_4858_26720673.1388851019403
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><p>In the following cases it is natural to allow copy elis=
ion to take place: </p>
<p>class A<br>
{<br>
&nbsp;&nbsp;&nbsp;&nbsp; double *v;<br>
&nbsp;&nbsp;&nbsp;&nbsp; std::size_t n; <br>
<br>
<br>
public:<br>
.. . .<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A operator+(A x) const &amp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp; for (std::size_t i =3D 0; i &lt; n; i++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x.v[i] +=3D=
 v[i];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp; return x; // copy elision will take place here<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color=3D"#0000ff">A =
operator+(const A&amp; x) &amp;&amp; // rvalue-ref-qualified<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp; for (std::size_t i =3D 0; i &lt; n; i++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v[i] =
+=3D x.v[i];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp; return std::move(*this); // At present, std::move is =
required here in order to get the desired effect. But it seems that &nbsp;<=
font color=3D"#274e13">return *this;</font> should be enough.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font><br>
.. . .<br>
}; </p>
<p>This proposal can be accessed through the following link: </p>
<div><a href=3D"https://dl.dropboxusercontent.com/u/35715999/copy_elision_f=
or_r_value_qualified_members.htm"><u><font color=3D"#0000ff">https://dl.dro=
pboxusercontent.com/u/35715999/copy_elision_for_r_value_qualified_members.h=
tm</font></u><font color=3D"#0000ff"></font></a></div><div>&nbsp;</div></di=
v>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_4858_26720673.1388851019403--

.