Among the many benefits of const qualification is to make an API more understandable, example:
template int function1(T const& in);
// clea
You could say this:
template
typename std::enable_if::value, int>::type
function(T && in)
{
// ...
}
where you have something like:
template struct immutable
: std::integral_constant::value> {};
template struct immutable
: std::true_type {};
This way, the template will only be usable if the universal reference is either a const-reference (so T = U const &
) or an rvalue-reference (so T
is not a reference).
That said, if the argument is not going to be changed, you could just use T const &
and be done with it, since there's nothing to be gained from binding mutably to temporary values.