Subject: Re: [boost] [xint] Third release is ready, requesting preliminary review
From: Peter Dimov (pdimov_at_[hidden])
Date: 2010-05-03 16:47:43


Chad Nelson:

> If that's the case, and GCC is doing that as it should, why would adding
> move semantics to the library provide any speed increase at all?

Consider something like

X f();
g( X );

int main()
{
    f( g() ); // #1
    f( -g() ); // #2
}

In #1, the compiler can eliminate all copies, if f is written in a
RVO-friendly way. (It won't be able to in general if there's more than one
return statement, or the return value is a ternary ?: expression.)

But in #2, there's going to be one allocation for the result of the unary
op-. Even if operator- takes its parameter by value and directly flips its
sign and returns it, I don't think that the compiler is allowed to allocate
the return value and the parameter at the same address.