Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #12103
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail |
|---|---|
| From | Dave Abrahams <dave@boostpro.com> |
| Newsgroups | comp.lang.c++.moderated, comp.lang.c++ |
| Subject | Re: C++11 rvalue reference question |
| Date | Tue, 6 Dec 2011 11:59:50 -0800 (PST) |
| Organization | unknown |
| Lines | 39 |
| Sender | lang-cpp-request@vandevoorde.com |
| Approved | musiphil@bawi.org |
| Message-ID | <m2aa7674i2.fsf@boostpro.com> (permalink) |
| References | <6b790921-3729-462f-8821-00dce04b5420@g7g2000vbd.googlegroups.com> |
| NNTP-Posting-Host | tjFtkqNXHK+C2ckWmoxv1IucHYij6X347ZwhN6yTABo= |
| Content-Type | text/plain |
| X-Trace | news.albasani.net JeT30CSKTewy+XIbNdXcYfE3Sf2kRBk4x6uFyVc1O7V6OvFsB/dLkLRclnzP5FELMfUqDPNbIawKvo2Hu46vgw== |
| X-Complaints-To | abuse@albasani.net |
| NNTP-Posting-Date | Tue, 6 Dec 2011 19:59:52 +0000 (UTC) |
| X-Mailer | Perl5 Mail::Internet v2.05 |
| X-Submission-Address | lang-cpp-submit@vandevoorde.com |
| Cancel-Lock | sha1:CVIdwqPozwndN3nM8AVi3+b1sPI= |
| X-Original-Date | Mon, 05 Dec 2011 22:39:33 -0500 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.c++.moderated:2622 comp.lang.c++:12103 |
Cross-posted to 2 groups.
Show key headers only | View raw
on Mon Dec 05 2011, Andrew Tomazos <andrew-AT-tomazos.com> wrote:
> In C++03 many times it was recommend to write such a function as
> follows:
>
> void f(O& out, const I& i)
> {
> .... // mutate result based on i
> if (,,,)
> throw E(...);
> }
>
> I i = ...;
> O o;
> f(o,i);
>
> I suspect this is to avoid the (potentially expensive) copy
> construction as the temporary O instance is copied from f's stack
> frame to the callers.
Probably, but the code above has always been a bad idea even in C++03.
Every compiler implements copy elision, so
O o = f(i);
is bound to be just as efficient, if not more so.
http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/
Cheers,
--
Dave Abrahams
BoostPro Computing
http://www.boostpro.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C++11 rvalue reference question Andrew Tomazos <andrew@tomazos.com> - 2011-12-04 21:38 -0800
Re: C++11 rvalue reference question Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-12-05 15:44 -0800
Re: C++11 rvalue reference question Arne L <a.luenser@googlemail.com> - 2011-12-05 15:51 -0800
Re: C++11 rvalue reference question SG <s.gesemann@gmail.com> - 2011-12-06 12:00 -0800
Re: C++11 rvalue reference question Dave Abrahams <dave@boostpro.com> - 2011-12-06 11:59 -0800
Re: C++11 rvalue reference question Ebenezer <woodbrian77@gmail.com> - 2011-12-11 00:52 -0800
csiph-web