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.
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
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.
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held