次のことを考慮してください。
ComplexObject foo()
{
ComplexObject temp;
//Do things with temp
ComplexObject result(temp, SOME_OTHER_SETTING); //1
//Do things with result. Do not use temp at all
return result; //2
}
ComplexObject foo()
{
ComplexObject temp;
//Do things with temp
ComplexObject result(std::move(temp), SOME_OTHER_SETTING); //1
//Do things with result. Do not use temp at all
return std::move(result); //2
}
ComplexObjectには、コピーコンストラクターよりもはるかに効率的な移動コンストラクターがあることを前提としています。
コンパイラは、ComplexObjectをそのブロックの残りの部分に使用できないことを認識しているため、最初のコードを2番目のコードに効果的に変換できますか?