I am trying to use a very simple log function using variadic templates in C++:
void log(){}
template <typename T, typename... Types>
void log(T first, Types... arg)
{
std::cout << first << " ";
log(arg...);
}
int main()
{
log(1,2);
log(3, "four");
log(5);
log(6,"seven",8,9,10,11,12);
log(13,14);
}
But in the output I am missing all the last arguments of the log function if the are integers (2, 5, 12 and 14) but not if they are strings ("four") !??. Why is that? What I am doing wrong?
output: 1 3 four 6 seven 8 9 10 11 13