On Sat, Feb 26, 2011 at 3:50 PM, Robert Jones <robertgbjones@gmail.com> wrote:
On Sat, Feb 26, 2011 at 3:27 AM, Nat Linden
<nat@lindenlab.com> 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.
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>