Boost logo

Boost :

From: Andrei Alexandrescu (andrewalex_at_[hidden])
Date: 2002-10-24 09:44:26


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

>> Every compiler outputs 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.

>For boost (as a lame attempt to make it on-topic for this list :) should
we add 'X x = f(); is preferable over 'X x( f() );' to the coding
guidelines?<

I put it into my team's coding standards three years ago. It was by far the
least popular guideline. Looks awful, but we were using it because we knew
it can be more efficient. Then, one day when we changed compilers, we hit
the declaration-vs-construction well-known ambiguity. We said some bad, bad
words and we ditched the guideline off.

The whole state of affairs with temporaries is terrible, in both syntax and
semantics. Ah, and while we're at it, anyone else hates the syntax and
semantics of member initializers?

Andrei

--
All new!  THE C++ Seminar: Oct. 28-30 in Vancouver, WA.
http://www.thecppseminar.com/

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