just a thought provoking question.
Normally I avoid declaring unneeded local variables, and often end up with statements such as:
Code: Select all
_whatevs.insert(a.someMethod()->GetX().ToPolar().Invert(), std::pair<int, new ZombieObject(35, 150, std::string())>)
Code: Select all
var x = a.someMethod()->GetX().ToPolar().Invert();
var *y = new ZombieObject(35, 150, std::string();
_whatevs.insert(x, y);
I ask, because in the first code sample all sub-expressions must be evaluated, then there must be some form of storage for each sub expression before the final result is inserted into _whatevs. I would guess in the first code example, each sub-expression result is stored on the stack.
In the second example we explicitly name the temporary storage (var x and y), whereas in the first example we do not.
Does the second method (in the general case) have any performance difference?
Clarification: By sub-expression I mean evaluating each parameter of the insert call (ie: a.someMethod()->GetX().ToPolar().Invert(), and the ZombieObject