The optimisation takes out ONE of the temporaries, but still requires a third parameter for a temporary.
Here''s the (pseudo)code from my book:
void Add( const Vector& __tempResult, const Vector& v1, const Vector& v2 ){__tempResult.Vector::Vector(); // Constructing!__tempResult.m_x = v1.m_x + v2.m_x;.. etc.}which is optimised from:void Add( const Vector& __tempResult, const Vector& v1, const Vector& v2 ){struct Vector retVal;retVal.Vector::Vector();retVal.m_x = v1.m_x + v2.m_x;retVal.m_y = v1.m_y + v2.m_y;__tempResult.Vector::Vector( retVal ); // Constructing!retVal.Vector::~Vector();return;}
I realise the pseudocode looks a bit odd, but I think it''s reasonably clear.
#pragma DWIM // Do What I Mean!
~ Mad Keith ~