Consider we need to implement a function f
with a templated argument T t
. The function should not copy t
and accept both rvalues
and lvalues
, therefore two implementations are possible:
template <class T>
void f(const T& t) { ... }
template <class T>
void f(T&& t) { ... }
If we want to change t
inside of f
or need to preserve the value category, we have to use the second version. So by this line of thought when and why would we go for the first option?