Re: "moveable data type" in comparison with "r-value reference"
In article <461e0500$0$79139$e4fe514c@news.xs4all.nl>,
"Sylvester Hesp" <s.hesp@oisyn.nl> wrote:
"Richard Smith" <richard@ex-parrot.com> wrote in message
news:gnfTh.824$NZ2.325@newsfe3-gui.ntli.net...
Just to correct a couple of typos that crept in. (I copied an old version
of the simple 'string' class into the post.)
string& operator=( string&& o )
{ string(o).swap(*this); return *this; }
And this needs another invocation of move:
{ string(std::move(o)).swap(*this); return *this; }
Just curious: why must a new (temporary) string be created? Wouldn't
o.swap(*this) suffice? I've read the latest proposed wording (N2118), and I
couldn't find anything about an expression like o.swap(*this) being
ill-formed as o is an r-value reference. As a matter of fact, 5/7
specifically states that, in this case (for the purpose of this function), o
is an lvalue of type string. Am I misinterpreting or missing something?
I believe you are correct Sylvester.
string& operator=( string&& o )
{ swap(o); return *this; }
should do it.
Nice example Richard, thanks.
-Howard
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]