4 Oct
2013
4 Oct
'13
9:43 p.m.
On 1 October 2013 05:22, Rob Stewart
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). -- Nevin ":-)" Liber mailto:nevin@eviloverlord.com (847) 691-1404