Subject: Re: [boost] [type_traits][function_types] Discard param const qualification, bug or feature?
From: Rob Stewart (robertstewart_at_[hidden])
Date: 2013-10-05 06:28:26
On Oct 4, 2013, at 5:43 PM, Nevin Liber <nevin_at_[hidden]> wrote:
> On 1 October 2013 05:22, Rob Stewart <robertstewart_at_[hidden]> wrote:
>> No, that should be int x. The reference is a pessimization for int. For larger types, const & is appropriate, though it will apply regardless of the top-level constness of the parameter. IOW, if the type is cheap to
>> copy, copy it, regardless of top-level constness. If it isn't, pass it by const &. That's what call_traits<T>::param_type does for you.
> It's more complicated than that. When you pass by value the compiler is allowed to assume there are no aliases to your object. Put another way,
> passing by reference can still be a pessimization for types larger than an int (and that is even before copy elision).
Granted, but I know of no way for a library to determine when pass-by-value would be better because of those optimizations.
I suppose you could offer a wrapper type that indicates the desire for pass-by-value, even when call_traits would pass by reference. The developer could try that to see whether profiling shows improvement.
(Sent from my portable computation engine)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk