|
Boost : |
From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2004-01-12 10:12:39
Howard Hinnant wrote:
> On Jan 12, 2004, at 4:46 AM, Daniel Frey wrote:
>
>> X operator+( const X& lhs, const X& rhs ) {
>> X nrv( lhs );
>> nrv += rhs;
>> return nrv;
>> }
>>
>> X operator-( X lhs, const X& rhs ) {
>> lhs += rhs;
>> return lhs;
>> }
>
>
> Nice example, I see what you mean. I hadn't thought about this case.
> The main characteristic between this and the case I was thinking about
> is the need to return the modified value. IIUC, this characteristic
> disables NRVO.
Of course. If there is no return value (RV), than neither the return
value optimization (RVO) nor the named return value optimization (NRVO)
can be applied. :)
> Fwiw, here is the case I was thinking about (and assumed Andrei was too):
> [snip]
You are right: In the case you showed it's better not to take the
parameter as a const reference but to pass it by-value. I just wanted to
point out that there is no general rule how you should take a parameter
which can be applied blindly without context.
Regards, Daniel
-- Daniel Frey aixigo AG - financial solutions & technology Schloß-Rahe-Straße 15, 52072 Aachen, Germany fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99 eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk