Let\'s say I want to implement a function that is supposed to process an object and return a new (possibly changed) object. I would like to do this as efficient as possible in C
The fastest way to do this is- if the argument is lvalue, then copy it and return that copy- if rvalue, then move it. The return can always be moved or have RVO/NRVO applied. This is easily accomplished.
Object process1(Object arg) {
return std::move(arg.makeChanges());
}
This is very similar to the canonical C++11 forms of many kinds of operator overloads.