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>
double *v;<br>
std::size_t n; <br>
<br>
<br>
public:<br>
.. . .<br>
A operator+(A x) const &<br>
{<br>
&nb=
sp; for (std::size_t i =3D 0; i < n; i++)<br>
&nb=
sp; {<br>
&nb=
sp; x.v[i] +=3D=
v[i];<br>
&nb=
sp; }<br>
&nb=
sp; return x; // copy elision will take place here<br>
}<br>
<br>
<font color=3D"#0000ff">A =
operator+(const A& x) && // rvalue-ref-qualified<br>
{ <br>
&nb=
sp; for (std::size_t i =3D 0; i < n; i++)<br>
&nb=
sp; {<br>
&nb=
sp; v[i] =
+=3D x.v[i];<br>
&nb=
sp; }<br>
&nb=
sp; return std::move(*this); // At present, std::move is =
required here in order to get the desired effect. But it seems that <=
font color=3D"#274e13">return *this;</font> should be enough.<br>
}</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> </div></di=
v>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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--
.