Let's consider two functions:
//Test functions
Object MakeObj(){/* processsing */};
Object ChangeObj(const Object& obj){/* processsing */};
//Then execute
Object test_obj = ChangeObj(MakeObj());
Is the execution safe?
Where is stored the 'Object' return value of the MakeObj()? Can I use a reference to that storage?
Or a temporary variable is necessary:
Object MakeObj(){/* processsing */}; Object ChangeObj(const Object& obj){/* processsing */}; Object tmp_obj = MakeObj(); Object test_obj = ChangeObj(tmp_obj);
Is there any performance gain or it is exactly the same, if the code from point 3 gets changed:
Object MakeObj(){/* processsing */}; Object ChangeObj(Object obj){/* processsing */}; //No reference here, so 'Object' value is created. Object test_obj = ChangeObj(MakeObj());
Is there a way to use "move" to avoid coping a big Object? E.g:
Object ChangeObj(Object&& obj){/* processsing */};
If yes, how it would look like?
What would be the fastest implementation (as less coping as possible) of those two functions above? Assumption: "Object MakeObj();" declaration cannot be changed.