Boost logo

Boost :

Subject: Re: [boost] rvalue ref best practices?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2012-06-12 12:13:50

On 06/12/2012 06:02 PM, Dave Abrahams wrote:
> on Mon Jun 11 2012, "Simonson, Lucanus J"<> wrote:
>>> In C++03, func_modify() would be the choice of performance-conscious
>>> programmers.
>>> In C++11, as we've told that "return by value is free" and the syntax
>>> is more elegant, I'm afraid everyone will write "func_factory".
>>> And func_factory() is less efficient when used in loops and other
>>> situations where resource reusing is essential.
>> If you aren't in a loop you probably don't care about performance. I
>> know I intend to stick with pass by reference. It is very useful to
>> clearly understand and be able to easily reason about the ownership of
>> resources in a program.
> If that's your primary concern, why on earth wouldn't you use
> pass-by-value?

On a slightly unrelated note, let me add that for fundamental types,
pass-by-value is also performance critical when functions aren't inlined.

In a loop, it is often very important to avoid going through the stack
and to keep as much as possible in registers.

Boost list run by bdawes at, gregod at, cpdaniel at, john at