REVIEW - C++ Move Semantics - The Complete Guide


C++ Move Semantics

The Complete Guide


Nicolai Josuttis


leanpub (2020)




Anthony Williams


March 2021



Verdict: Highly recommended.

This is the latest book by Nicolai Josuttis, and it is as good as you might expect; the moniker of ‘The Complete Guide’ is well earned. I’ve encountered people claiming that the mere existence of this book demonstrates that move semantics in C++ are too complicated. This is definitely not the case, and the book clearly demonstrates that for the vast majority of cases, move semantics are easy to use and understand.

It’s an easy read with plenty of examples, guiding you through all aspects of move semantics. The book starts off with a bit of history, demonstrating why move semantics are needed, then shows how you can take advantage of them with standard library types such as `std::string` and class templates such as `std::vector`, and how the compiler will often use them automatically, with no visible marker in the code.

Moving on, the book covers the details of the language features that make move semantics work, including rvalue references, "universal" references, and overload resolution rules.

The requirements for move semantics on your own classes are explained clearly, with a whole section on how objects should behave after being used as the source of a move operation. This "moved from" state has been the focus of a lot of active discussion. Nico highlights the basic requirements, and explains the choices you then face as a developer, with straightforward recommendations.

The book also covers the support in the standard library for facilitating your use of move semantics, such as the use of `std::move_iterator` to move objects around when using algorithms.

Overall, this is an excellent book, well worth a read for anyone working with modern C++ code.


Your Privacy

By clicking "Accept All Cookies" you agree ACCU can store cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

By clicking "Share IP Address" you agree ACCU can forward your IP address to third-party sites to enhance the information presented on the site, and that these sites may store cookies on your device.