An rvalue reference uses && to refer to a right-hand-side value, including a temporary, so its resources can be transferred instead of copied. section 2.1 section 2.0
Mistake: copying a uniquely owned object and then repairing ownership manually. The copy constructor duplicates data before deleting the source data, creating unnecessary cost and fragile invalidation rules. section 2.1
Listing 2.1 A uniqueness-preserving assignment operator with heavy cost
class TextSection {
// assume a clever implementation
};
class Page {
private:
TextSection* headers;
TextSection* body;
public:
Page(TextSection* h) : headers(h), body(new TextSection()) {}
Page(Page& o);
~Page() { if (body) delete body; }
};
Page::Page(Page& o) {
if (this == &o)
return;
body = new TextSection(*o.body);
delete o.body;
o.body = 0;
headers = o.headers;
o.headers = 0;
}
int main() {
Page p1(new TextSection());
Page p2 = p1; #1
return 0;
}
The problematic Page example copies body, deletes the source body, and nulls the source pointers; extensive data makes the duplication expensive. section 2.1
Modernize the transfer with a move constructor or move assignment operator. The destination takes ownership, while the source is invalidated so its former data cannot be accessed. section 2.1
Listing 2.2 A uniqueness-preserving assignment operator with negligible cost
class TextSection {
// assume a clever implementation
};
class Page {
private:
TextSection* headers;
TextSection* body;
public:
Page(TextSection* h) : headers(h), body(new TextSection()) {}
Page(const Page& o) : headers(o.headers), body(new #1
TextSection(*o.body)) {}
Page(Page&& o) : headers(o.headers), body(o.body) { #2
o.headers = nullptr; #3
o.body = nullptr;
}
~Page() { delete body; }
};
int main() {
Page p1(new TextSection());
Page p2 = std::move(p1); #4
return 0;
}
The corrected Page example transfers pointers through Page(Page&&) and calls std::move(p1), avoiding data duplication and nulling the moved-from source. section 2.1

