In a previous question, it appeared that a plain return-by-value function always copies its return
argument into the variable being assigned from it.
Is this required by the standard, or can the function be optimized by constructing the 'assigned to' variable even within the function body?
struct C { int i; double d; };
C f( int i, int d ) {
return C(i,d); // construct _and_ copy-construct?
}
int main() {
C c = f( 1, 2 );
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…