Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #12408
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Subject | Re: Writing move constructors and move assignment |
| Date | 2011-12-12 13:45 +0000 |
| Message-Id | <pan.2011.12.12.13.45.16.498000@nowhere.com> |
| Newsgroups | comp.lang.c++ |
| References | <3e5a9cb8-013e-41ea-8ba8-5f1133ebf453@c13g2000vbh.googlegroups.com> |
| Organization | Zen Internet |
On Mon, 12 Dec 2011 04:11:10 -0800, Andrew Tomazos wrote:
> Foo(Foo&& that)
> {
> ???
p = that.p;
that.p = NULL;
> }
>
> Foo& operator= (Foo&&)
Foo& operator= (Foo&& that)
> {
> ???
if (this != &that) {
p = that.p;
that.p = NULL;
}
return *this
> }
> };
> What role does std::move play if any in this case?
You can re-write the move constructor using the move assignment
operator and std::move as:
Foo(Foo&& that)
{
*this = std::move(that);
}
std::move just lets you get an rvalue reference for an lvalue, to cause
the correct overload to be used.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
Writing move constructors and move assignment Andrew Tomazos <andrew@tomazos.com> - 2011-12-12 04:11 -0800 Re: Writing move constructors and move assignment Marc <marc.glisse@gmail.com> - 2011-12-12 13:15 +0000 Re: Writing move constructors and move assignment Nobody <nobody@nowhere.com> - 2011-12-12 13:45 +0000
csiph-web