Move-constructing an object

When moving an object, the destination object steals the resource straight from the source object, and the source object is reset, as illustrated in the following image. As you can see, it is very similar to swapping, except that the moved-from object does not have to receive the resources from the moved-to object:

auto a = Object{}; 
auto b = std::move(a); // Tell the compiler to move the resource into b 

The following image illustrates the process:

Moving resources from one object to another
Moving objects only makes sense if the object type owns a resource of some sort (the most common case being heap-allocated ...

Get C++ High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.