Type template parameter deduction strips cv-qualifiers and ref-qualifers (It also converts array types to pointer types, and function types to function pointer types.)
If you want the reference to be part of the deduced type, add it to the declarator. (The same goes for const
.)
template<class... Ts>
void f(Ts&... args);
If you want the deduced type to be either lvalue reference or rvalue reference depending on whether the argument is an lvalue or rvalue, use a "universal reference".
template<class... Ts>
void f(Ts&&... args);
(Despite what the latter looks like, it does not mean "accept rvalue only". This is much rarer. For this case, see How to make template rvalue reference parameter ONLY bind to rvalue reference?)
Note: There is no way to make a function that takes its argument by reference only if the variable passed in was declared as a reference. This is because a reference always behaves exactly like the object it refers to (except when decltype
is applied).