Subject: Re: [boost] [type_traits][function_types] Discard param const qualification, bug or feature?
From: Nevin Liber (nevin_at_[hidden])
Date: 2013-10-04 17:43:03
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).
-- Nevin ":-)" Liber <mailto:nevin_at_[hidden]> (847) 691-1404