Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Daniel Krügler <daniel.kruegler@googlemail.com> |
|---|---|
| Newsgroups | comp.std.c++ |
| Subject | Re: x = f(move(x)) |
| Date | 2011-09-10 00:30 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <j4cluj$isi$1@dont-email.me> (permalink) |
| References | <8jV9q.191323$k33.95339@en-nntp-13.dc1.easynews.com> |
On 2011-09-08 23:47, Joe Gottman wrote:
>
> Suppose I have the following pair of functions:
>
> string foo(const string &x); // Makes a copy of x, modifies, and returns
> it.
>
> string foo(string &&x) // Modifies and returns x itself, since x is an
> rvalue.
>
> Given these functions, does the following code work?
>
> int main()
> {
> string x = "hello";
> x = foo(move(x));
> return 0;
> }
I believe this should work because of the sequencing rules.
> I think it doesn't, because a move-constructor or move-assignment
> operator might modify its input parameter, but I'm not sure.
As of C++11 there has been added special wording to "5.17 Assignment
and compound assignment operators [expr.ass]":
"In all cases, the assignment is sequenced after the value
computation of the right and left operands, and before the value
computation of the assignment expression."
HTH & Greetings from Bremen,
Daniel Krügler
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to comp.std.c++ | Previous | Next — Previous in thread | Next in thread | Find similar
x = f(move(x)) Joe Gottman <josephgottman@comcast.net> - 2011-09-08 14:47 -0700 Re: x = f(move(x)) Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-09-10 00:30 -0700 Re: x = f(move(x)) SG <s.gesemann@gmail.com> - 2011-09-10 00:30 -0700
csiph-web