The Move Constructor That You Have to Declare, Even Though You Don’t ... -- Raymond Chen
You may have a class that you want to participate in RVO or NRVO, but you also don’t want it to be moved. For example, it may contain a std::mutex, which is not movable. But you nevertheless have to declare a move constructor. What can you do?
The Move Constructor That You Have to Declare, Even Though You Don’t Want Anyone to Actually Call It
by Raymond Chen
From the article:
Blah blah blah C++ return value optimization (RVO), named return value optimization (NRVO), and copy elision.
RVO support was optional in C++11 but became mandatory in C++17. NRVO support remains optional (but recommended).
To allow NRVO in C++17 (or RVO and NRVO in C++11), a move constructor must be available, even though the compiler will not call it if the optimization is employed.
You may have a class that you want to participate in RVO or NRVO, but you also don’t want it to be moved. For example, it may contain a
std::mutex, which is not movable. But you nevertheless have to declare a move constructor. What can you do?Declare the move constructor, but...

Sorting algorithms have been thoroughly studied. Kevlin Henney takes an unexpected paradigm journey into sleep sort.
std::move can allow the efficient transfer of resources from object to to object. Andreas Fertig reminds us that using std::move inappropriately can make code less efficient.
Is it possible to extend a value type in C++? Alf Steinbach describes how to extend enum values.
Guarded Suspension applies a unique strategy to deal with mutation. It signals when it is done with its modification.
Recently, our team at Meteksan Defense is upgrading its development environment to use newer versions of many tools and programming languages. One of the more difficult transitions has been the upgrade of our C++11 code base to C++17 for our embedded applications.