In the following code
std::string OtherFunc();
std::string MyFunc() {
if (condition1) return "result 1";
if (condition2) return "result 2";
return OtherFunc();
}
Will MyFunc() enable copy elision (for the return string from OtherFunc())? I know I can write
std::string MyFunc() {
std::string ret;
if (condition1) {
ret = "result 1";
return ret;
}
if (condition2) {
ret = "result 2";
return ret;
}
ret = OtherFunc();
return ret;
}
to 100% sure copy elision enable. But I think the 2nd code is very cumbersome.