Consider the following (not working!) example:
#include <iostream>
template <typename type> void print(const type & item)
{
std :: cout << item << std :: endl;
}
template <typename... types> void printall(const types & ... items)
{
print(items)...;
}
int main()
{
printall(1, 2, "hello");
}
Here I have a function print
that simply prints out its argument, and a variadic function printall
that accepts a pack of arguments. Now, what I would like to do is to simply have printall
apply print
to each element of the pack items
. How can I get that done?
Note: I am not asking how to print a pack of values. I am aware of the existence of fold expressions and I know I could just throw the whole items
in std::cout
using them. Here print
is just an example, could be any function.
How can I get that done? This sounds like something that should remarkably simple to do and yet I couldn't find any (reasonable) syntax to do it.