Most concise way to disable copy and move semantics
You can write a simple struct
and inherit from it:
struct crippled
{
crippled() = default;
crippled(const crippled&) = delete;
crippled(crippled&&) = delete;
crippled& operator=(const crippled&) = delete;
crippled& operator=(crippled&&) = delete;
};
Usage:
struct my_class : crippled
{
};
int main()
{
my_class a;
auto b = a; // fails to compile
}
According to this chart (by Howard Hinnant):
The most concise way is to =delete
move assignment operator (or move constructor, but it can cause problems mentioned in comments).
Though, in my opinion the most readable way is to =delete
both copy constructor and copy assignment operator.