On Oct 4, 2013, at 5:43 PM, Nevin Liber
On 1 October 2013 05:22, Rob Stewart
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. ___ Rob (Sent from my portable computation engine)