Boost logo

Boost Users :

From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2003-04-24 10:56:40


dick.bridges_at_[hidden] wrote:
> I don't understand C++ well enough to grok a compiler's interpretation
of
> the code, but I seems like I'm creating an extra copy for the return.
<snip>

Logically the local variable is copied to the the caller, but since the
type
of the returned expression matches the return type the compiler is
allowed
to optimise away that copy, even though the return type has a
user-defined
copy constructor. In this case you always return a certain named
variable,
so the compiler can arrange to construct it in the memory location where
the
caller expects the returned value. This is called the
named-return-value
optimisation, or NRVO.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net