Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2002-10-14 02:04:12


>From: "Gabriel Dos Reis" <gdr_at_[hidden]>

>Terje Slettebø <tslettebo_at_[hidden]> writes:

>| It appears from this that RVO and NRVO are treated in the same way - both
>| are allowed to elide copying, even if the copy would have a side effect.

>In theory, yes; in practice, no. GCC, for example, has been able to
>elide unnamed temporary looong before it implemented the "true" NRVO
>(and that inflences part of its standard library implementation; I
>didn't have the time to go through it and take advantages of NRVO;
>maybe something to do in GCC-3.4)

>| >From this, as mentioned in another posting, could this also hold for a
value
>| parameter (it's a local object, as well)? I.e. like the following:
>|
>| inline Test operator+(Test t1,const Test &t2)
>| {
>| t1+=t2;
>|
>| return t1; // Can NRVO be applied here?
>| }

>Here, an implementation may elide the copy-constructor call to
>initialize t1. While in some sense a parameter maybe be viewed as a
>local variable, it is a local variable that is initialized in the
>caller site, so it is not clear whether NVRO can be blatantly applied.
>However, the same 12.8/15 maybe be applied if the implementation can
>prove it to elide the second copy-constructor call. But we're getting
>lots of "if". :-)

Thanks for the reply.

Regards,

Terje


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