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


Author: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Date: Sat, 4 Jan 2014 04:48:41 -0800 (PST)
Raw View
------=_Part_731_3407361.1388839721092
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 affect
    }
.. . .
};

The proposal can be accessed through the following link:
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_731_3407361.1388839721092
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>In the following cases it is natural to allow copy el=
ision to take place:</div><div>&nbsp;</div><div>class A<br>{<br>&nbsp;&nbsp=
;&nbsp; double *v;<br>&nbsp;&nbsp;&nbsp; std::size_t n;&nbsp;&nbsp;&nbsp; <=
br>&nbsp;<br>&nbsp;<br>public:<br>&nbsp;. . .<br>&nbsp;&nbsp;&nbsp; A opera=
tor+(A x) const &amp;<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp; for (std::size_t i =3D 0; i &lt; n; i++)<br>&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp; x.v[i] +=3D v[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return x; //=
 copy elision will take place here<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;<br>&nb=
sp;&nbsp;&nbsp; <font color=3D"#0000ff">A operator+(const A&amp; x) &amp;&a=
mp;&nbsp; // rvalue-ref-qualified<br>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (std:=
:size_t i =3D 0; i &lt; n; i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; {<br>&nbsp;&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; }<br>=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return std::move(*this); // At p=
resent, std::move is required here in order to get the desired affect<br>&n=
bsp;&nbsp;&nbsp; }</font><br>. . .<br>};</div><div>&nbsp;</div><div>The pro=
posal can be accessed through the following link:</div><div><a href=3D"http=
s://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</a></div><div>&nbsp;</div><div>&nbsp;</div><=
/div>

<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_731_3407361.1388839721092--

.