|
Boost Users : |
Subject: Re: [Boost-users] [Filesystem] V3 interface inconsistency
From: Nat Linden (nat_at_[hidden])
Date: 2011-02-26 21:24:31
On Sat, Feb 26, 2011 at 3:50 PM, Robert Jones <robertgbjones_at_[hidden]>wrote:
On Sat, Feb 26, 2011 at 3:27 AM, Nat Linden <nat_at_[hidden]> wrote:
>
>>
>> An accessor that returns a const reference to a data member is little
>> better than direct read access to the data member. The reason we use
>> accessors in the first place is to permit us to later introduce additional
>> logic if need be: to return a computed value. But returning a reference
>> forbids that.
>>
>> Stepping back a little further I'd be inclined to ask why the accessor
> exists at all. The great get/set debate!
>
/me backs slowly away from potential rwar
>
> Pass by const reference, but return by value.
>>
>
> That would seem to fly in the face of copy elision - see
> http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/
>
>
Hmm! Thanks for passing me the reference (as it were).
So let's say my real point is: return by value. I may have to rethink my
policy on accepting parameters.
<veering dangerously off topic>For an rvalue actual argument, I think I see
that a modern compiler can treat a value parameter as efficiently as a const
reference parameter. But across translation units, wouldn't an lvalue actual
argument necessarily be more efficient when received by a const reference
than by a value parameter? Especially if the function body only examines the
parameter without needing to copy it?</veering>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net