Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++.moderated > #2622
| From | Dave Abrahams <dave@boostpro.com> |
|---|---|
| Newsgroups | comp.lang.c++.moderated, comp.lang.c++ |
| Subject | Re: C++11 rvalue reference question |
| Date | 2011-12-06 11:59 -0800 |
| Organization | unknown |
| Message-ID | <m2aa7674i2.fsf@boostpro.com> (permalink) |
| References | <6b790921-3729-462f-8821-00dce04b5420@g7g2000vbd.googlegroups.com> |
Cross-posted to 2 groups.
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++.moderated | 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