Boost logo

Boost :

From: Gabriel Dos Reis (gdr_at_[hidden])
Date: 2002-10-13 12:51:13


Terje Slettebø <tslettebo_at_[hidden]> writes:

| >From: "Gabriel Dos Reis" <gdr_at_[hidden]>
|
| >Terje Slettebø <tslettebo_at_[hidden]> writes:
|
| >| Could someone point me to the part of the standard that allows for RVO
| and
| >| NRVO?
|
| >12.8/15.
|
| Thanks. :) It says:

[...]

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

-- Gaby


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