Move Constructor Observations
Although using an rvalue reference enables move semantics, it doesn’t magically make it happen. There are two steps to enablement. The first step is that the rvalue reference allows the compiler to identify when move semantics can be used:
Useless two = one; // matches Useless::Useless(const Useless &)Useless four (one + three); // matches Useless::Useless(Useless &&)
The object one is an lvalue, so it matches the lvalue reference, and the expression one + three is an rvalue, so it matches the rvalue reference. Thus, the rvalue reference directs initialization for object four to the move constructor. The second step in enabling move semantics is coding the move constructor so that it provides the behavior ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access