Subject: Re: [boost] [optional] generates unnessesary code for trivial types
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-01-30 18:09:02
on Mon Jan 30 2012, Kim Barrett <kab.conundrums-AT-verizon.net> wrote:
> On Jan 30, 2012, at 3:49 PM, Simonson, Lucanus J wrote:
>> I like pass by reference and return a bool over returning an
>> optional for performance because we allocate memory for the result
>> of the function outside of the function call and there is no
>> transfer of ownership of the result.
> Personally, I like returning values rather than modifying arguments.
> But more importantly, the caller might not even be able to construct
> that object to be passed by reference, due to lack of access to an
> appropriate combination of constructor and initialization arguments,
> such as when the class has no default constructor.
>> Even with move semantics, you have just changed an unnecessary copy into cheaper unnecessary move.
> If one cares about performance and one's compiler is not capable of
> doing RVO for optionals, perhaps one should be looking for a better
> compiler, and not just for better handling of optionals.
IIRC, RVO is now mandated where it's possible, so the whole move
argument is kina moot.
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk