Hello I have this example about variadic function templates and patterns:
int& neg(int& x){ x = -x; return x;}
void f(int& x){
std::cout << x << ", ";
}
template <typename T, typename...Args>
void f(T& x, Args&...args){
f( neg(args)...);
}
int main(){
int x = 1, y = 2, z = 3, a = 4;
f(x, y, z, a);
std::cout << x << ", " << y << ", " << z << ", " << a << '\n';
cout << '\n';
}
The output:
-4, 1, -2, 3, -4
I don't know why I get this output and why shouldn't it be
-1, -2, -3 -4
?Can someone explain to me what happens exactly when applying the pattern to the function argument pack:
f(neg(args)...;
? Thank you so much!It looks to me that it starts the pattern in reverse order I mean from the end to the beginning. isn't it?