November 1999
Intermediate to advanced
336 pages
6h 29m
English
When the compiler fails to apply the RVO, you can give it a gentle nudge in the form of the computational constructor (originally attributed to J. Shopiro [Car92, Lip96I].) Our compiler did not apply the RVO to Version 1:
Complex operator+ (const Complex& a, const Complex& b)
// operator+ version 1.
{
Complex retVal;
retVal.real = a.real + b.real;
retVal.imag = a.imag + b.imag;
return retVal;
}
This implementation created a default Complex object and deferred setting its member fields. Later it filled in the member data with information supplied by the input objects. The production of the Complex retVal object is spread over multiple distinct steps. The computational constructor collapses these steps into a single ...
Read now
Unlock full access