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
>>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

Boost list run by bdawes at, gregod at, cpdaniel at, john at