Yet another "why must std::move
prevent the (unnamed) return-value-optimization?" question:
Why does std::move prevent RVO? explains that the standard specifically requires that the function's declared return type must match the type of the expression in the return
statement. That explains the behavior of conforming compilers; however, it does not explain the rationale for the restriction.
Why do the rules for RVO not make an exception for the case where the function's return type is T
and the type of the return
expression is T&&
?
I also am aware that implementing such things in compilers doesn't come for free. I am suggesting only that such an exception be allowed but not required.
I also am aware that return std::move(...)
is unnecessary since C++11 already requires that move semantics be used when the RVO can't be applied. Nevertheless, why not tolerate an explicit request for optimization instead of turning it into a pessimization?
(Aside: Why are the return-value-optimization
and rvo
tags not synonyms?)
Aucun commentaire:
Enregistrer un commentaire