When I want a function to return me a container:
vector<T> func(){
vector<T> result;
...
return result;
}
To be used in the following way:
vector<T> result = func();
In order to avoid the overhead of copying my container I often write the function so that it returns nothing but accept a non-const instance of the container.
void func(vector<T>& result){
result.clear();
...
result;
}
To be used in the following way:
vector<T> result;
func(result);
Is my effort meaningless because I can be sure that the compiler always uses the return value optimization?