Say I have a simple struct that contains a vector and defines a copy assignment operator, and a function that returns this struct, like so:
struct SimpleStruct
{
vector< int > vec1;
operator=( SimpleStruct& other )
{
vec1 = other.vec1;
}
}
SimpleStruct GetStruct();
As I understand it, because I've declared a copy assignment operator, the compiler won't automatically generate a move constructor for SimpleStruct.
So if I use the GetStruct
function like this:
SimpleStruct value = GetStruct();
Is the compiler smart enough to move rather than copy the vector when I say vec1 = other.vec1;
? Or will I need to explicitly define a move constructor/assignment operator for SimpleStruct to take advantage of a vector move?