In C++, it seems that a parameter may be normally expanded with ...
directly after the parameter pack's name. For example,
template <class... Tys>
void function(Tys... params) {
function(params...);
}
However, when using std::forward
, the ...
goes seemingly after the parameter pack's name. For example,
template <class... Tys>
void function(Tys... params) {
function(std::forward<Tys>(params)...); // The '...' is outside the parenthesis of 'params'
}
My question is why is there a difference? Why is the following code incorrect?
template<class... Tys>
void function(Tys... params) {
function(std::forward<Tys>(params...));
}
At what point in the parameter pack expanded? I probably am not fully understanding how std::forward
works or how it forwards arguments perfectly.
I appreciate any answers!