I have a template function with varargs template arguments, like this
template
void ascendingPrint(
I think instead of reversing the arguments, you can reverse your logic! For example reverse the operations on arguments.
template
void ascendingPrint(const T& x)
{
cout << x << " ";
}
template
void ascendingPrint(const T& t, Args... args)
{
ascendingPrint(t); // First print `t`
ascendingPrint(args...); // Then print others `args...`
}
template
void descendingPrint(const T& x)
{
cout << x << " ";
}
template
void descendingPrint(const T& t, Args... args)
{
descendingPrint(args...); // First print others `args...`
descendingPrint(t); // Then print `t`
}
int main()
{
ascendingPrint(1, 2, 3, 4);
cout << endl;
descendingPrint(1, 2, 3, 4);
}
Output
1 2 3 4
4 3 2 1