[LC++]Using the "return value optimization"
Vincent Penquerc'h
vincent at qubesoft.com
Mon Aug 13 19:31:04 UTC 2001
> return int(doSomething(***here***, parameter));
>
> Unfortunately no such syntax exists (to my knowledge). Is
> there any way around my problem?
Well, try it, and you'll see it actually works, if your
doSomething function returns the int:
int doSomething(int const& parameter);
...
return int(doSomething(parameter));
(well, it should anyway). C++ sees basic types as classes as
well, and this is a constructor call.
*BUT*:
ret val opt is useful to avoid creation of temporaries (as
calling ctor/dtor can be painful in terms of speed and/or
bloat). An int has no function ctor/dtor, so you would gain
nothing at all: it will be possibly an extra move between
registers, which is likely to be removed by one of the
optimizations passes anyway.
--
Lyrian
More information about the tuxCPProgramming
mailing list