Based on the recipe found here, I wrote the following:
void printInt(int a) {std::cout << a << std::endl;}
template <typename... Args>
void f(const Args &... args) {
auto temp = {(printInt(args), void(), 0)...};
auto a = temp; temp = a;
}
Two questions:
What does this syntax mean:
{(printInt(args), void(), 0)...}
?I added the line
auto a = temp; temp = a;
in order to not get a warning about the unused variabletemp
. Is there a better way?
After the explanations in the reply and the comments, the only question that remains is: why doesn't C++ allow for this:
template <typename... Args>
void f(const Args &... args) {
printInt(args)...;
}
This question was asked in the cited post, but did not receive any answer.