From -718718563646651772
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,f5d433881cc29cff
X-Google-Attributes: gidf78e5,public
From: bparker@gil.com.au (Brian Parker)
Subject: Re: Named return value optimisation- reprise.
Date: 1997/06/17
Message-ID: <33a71f76.1703390@news.ipswich.gil.com.au>#1/1
X-Deja-AN: 249189499
References: <33a345bf.7425526@news.ipswich.gil.com.au> <33A478C1.329@acm.org> <u9pvtnuemu.fsf@yorick.cygnus.com> <33A65B20.595D@aom.ericsson.se> <5o644g$3fj$1@toralf.uib.no>
X-Original-Date: Wed, 18 Jun 1997 00:22:15 GMT
Organization: Global Info-Links News Server
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBM6cpUky4NqrwXLNJAQHMdQIAvAfgqlbBZRVZ0puI7xiu65W1nU6zMdJ+ 7+E0beNHW5ul7svEKWHFv3tH+K56J777/EljQNwYuIwOqoZ5FOmAqA== =SobO
Newsgroups: comp.std.c++
Originator: austern@isolde.mti.sgi.com


On 17 Jun 1997 09:25:18 PDT, boukanov@sentef1.fi.uib.no (Igor
Boukanov) wrote:
>...
>> vector<int> reverse_vec(vector<int> v)
>> {
>>         // v passed by-value, so we can safely modify it in-place
>>         reverse(v.begin(), v.end());
>>         return v;
>> }
>
>As I undestand the current rule the argument for reverse_vec should be copied 
>because it is used when "reverse(v.begin(), v.end())" is called.
>The rule just permits not to copy v on the return. So the example output
>should be 5,5,5,5 even with the optimisation on. 

No, in fact the draft gives exactly this case as an example in 12.8/15

"
void g(Thing t) {t.func( ); }

int main()
{
	Thing t2;
	...

	g(t2);
}

Although g uses its parameter, the call to g(t2) does not need to copy
t2 because t2 is not used again after it is passed to g."

(as always, this depends upon your definition of "object is used".)

,Brian Parker (bparker@gil.com.au)
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



