Boost logo

Boost :

From: Marc Duflot (m.duflot_at_[hidden])
Date: 2002-10-24 10:38:16


Andrei Alexandrescu wrote:

> "Daniel Frey" <daniel.frey_at_[hidden]> wrote in message
> news:3DB7F6B3.AAB353CC_at_aixigo.de...
>>The question is, why 'X x( f() );' is different from 'X x = f();'.<
>
> Yes. The latter is equivalent to X x = X(f()) so it is allowed to create
> an extra copy.

This is why the results are so surprising. It is indeed in the case
'X x = f();' that the NRVO is applied and the copy is removed. Intel C++ and
SGI C++ miss the opportunity to apply the NRVO for 'X x( f() );'
 
>>> Every compilers output nothing for X( f() ) and X( g() ).
>
>>This is the most surprising result, at least to me. As all compilers
> seem to agree, I wonder if I missed some fundamental point. I would not
> expect that compilers are allowed to remove the objects completly. Is it
> allowed?<
>
> I suggest we do the measurement with main() in one file and everything
> else in another file, so the compiler can't inline the calls.

I did it and got the same results.
 

-- 
Marc Duflot
http://vesta.ltas.ulg.ac.be/~duflot/

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk