This question is in the context of c++11.
When a variable which is allocated on the stack is returned from a function, is the copy optimized out if the object defines a move constructor?
I have this piece of code, the move constructor and the function I described above:
MyBigObject(MyBigObject&& other) {
// code elided
}
MyBigObject createTheObject() {
MyBigObject emptyObj;
// initialize obj with stuff
return emptyOBj;
}
Does this definition of the move constructor mean that all returns by values are converted automatically to 'moves'? Or is the copy going to be optimized out by some other mechanism other than move?
How would this code behave if there were no move constructor defined? In that case does the full copy happen instead?