In C++98, the C++ compiler could automatically generate copy constructor and copy assignment operator via member-wise copy, e.g.
struct X {
std::string s;
std::vector<int> v;
int n;
};
The compiler automatically generates copy constructor and copy assignment operator for X
, using member-wise copy.
But how do things change in C++11 with move semantics?
Are the move constructor and move assignment operator automatically generated, like copy constructors and copy assignment operators?
Are there cases in which move operations are not automatically generated?
From the standard Ch. 12 - Special member functions
Par 12.8 Copying and moving class objects (emphasis mine)
Then
11
explains the rules for deleting the defaulted move constructorOn the complexity of it all *
The rules can be somewhat overwhelming. It's good to use some technique to bypass the complexity. Examples are :
* points made in the comments by myself (1) and dyp (2)
Nikos Athanasiou gave a good answer but I wanted to add this tool that I think is very useful.
Here is a screenshot of Howard Hinnant's presentation "Everything You Ever Wanted To Know About Move Semantics (and then some)" from ACCU 2014 conference which I think is a very good reminder of the rules of automatic generation of special members:
Clarification from Mr Hinnant from the comments:
I recommend reading the slides to get the progressive construction of this table and have a detailed explanation of how and why we have this now.
Other presentations can be found there: http://accu.org/index.php/articles/1901