Let's say we have this situation
std::string v_1()
{
return "name";
}
std::string test = v_1();
Is RVO applied here? I think that the answer is no, because one the rules to apply RVO is: "If a function returns a class type by value, and the return statement's expression is the name of a non-volatile object with automatic storage duration, which isn't the function parameter, or a catch clause parameter, and which has the same type (ignoring top-level cv-qualification) as the return type of the function, then copy/move is omitted" And in this situation the object returned does not have the same type of the return type of the function, but I'm not 100% that RVO is not applied here.
Thank you very much.
Aucun commentaire:
Enregistrer un commentaire