stelios xanthakis wrote in news:8a018872.0310160201.29cb99d0
@posting.google.com:
[color=blue]
>
> That is interesting. So "f()", or any other function which
> uses RVO is actually used as a constructor. Right? Right?[/color]
Well that one way of looking at it, though note the word optimization,
I understand this as meaning optional feature. i.e. a compiler doesn't
have to do it, but good ones will.
IIUC optimization also means the compiler doesn't have to do it
every time, i.e. it isn't required to be consistant about when
it does the optimization.
[color=blue]
>
> Except from the case of operator overloading, the only application
> of RVO functions is to be used for chosing an alternative function
> to do the initialization of members 'n stuff. Yes?
>[/color]
No, any function that returns by value can benifit. Typicaly:
class_type a;
a = f();
will require f() to return a temporary which is then assigned with
operator =( class_type const & ) to a. With RVO/NRVO this temp can
be constructed directly by f(), an optimization. Also useful in
expresion's like g(f()); g{}'s temp argument can again be constructed
directly by f().
[color=blue]
> I was thinking: what's the difference between making f() a member
> function instead of an RVO non-member? It seems that the RVO case has
> the advantage of bypassing the normal constructor calls -- an
> authority given by the standard.[/color]
It does, but as I noted previously the copy-ctor needs to be accesible
even though it doesn't get called, also because its an optimisation you
can't use (N)RVO as a way of changing the meaning of your code.
[color=blue]
>
> Any other application of RVO, I'm missing?
>[/color]
Its just a Good Thing(tm).
Rob.
--
http://www.victim-prime.dsl.pipex.com/