Optimizing the number of constructor calls
问题 At work we have a class with an expensive constructor so we would like it to be called as few times as possible. We looked through the uses of it and tried to make the code more RVO friendly so to say. However we found a quirk in the g++ compiler where we didn't understand what happened. Please consider the two implementations of operator+ const Imaginary Imaginary::operator+(const Imaginary& rhs) const { Imaginary tmp(*this); tmp.append(rhs); return tmp; } and const Imaginary Imaginary: