vendredi 31 juillet 2015

Passing each argument of a variadic function template into a function that returns void

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:

  1. What does this syntax mean: {(printInt(args), void(), 0)...}?

  2. I added the line auto a = temp; temp = a; in order to not get a warning about the unused variable temp. Is there a better way?

Aucun commentaire:

Enregistrer un commentaire