I'm in a bit of a dilemma. I want to know what the difference is between Foo and Meh. I wrote both of them and I did not like Foo so I wrote Meh. They both work but is there an overhead to Meh? Is there anything bad about Meh?
The reason I'm asking is because everywhere I look on the internet, I see coders writing Variadic templates the same way Foo is written. With a helper function. I dislike using a helper function for such a thing so I wrote Meh which uses an initializer list and a for-ranged loop to go through the packed parameters.
What's the pros and cons of using Foo vs. Meh? Are there downsides? Does one have an overhead? Which do you prefer?
#include<iostream>
template<typename T>
void Foo(T Argument)
{
std::cout<<Argument;
}
template<typename First, typename... Args>
void Foo(First ArgumentOne, Args... Remainder)
{
std::cout<<ArgumentOne;
Foo(Remainder...);
}
template<typename First, typename... Args>
void Meh(First ArgumentOne, Args... Remainder)
{
for (First I : {ArgumentOne, Remainder...})
{
std::cout<<I;
}
}
int main()
{
Foo(1, 2, 3, 4);
std::cout<<std::endl;
Meh(1, 2, 3, 4);
//Both of the above print "1234".
}