Here's a code cleanliness issue that you will want to be aware of. Say a user inputs the option. So you have some variable Number x
which might be One
or Two
. If you want to call foo()
, you will need to do...
if (x == One)
foo<const char *, One>("asd");
else
foo<const char *, Two>("asd");
where as, if you used the alternative way (your suggestion number two), you could simply do:
foo<const char *>("asd", x);
Now, if in this function, it would be very beneficial to have those possible branches optimized out, then sure. But otherwise, I think you're just making life difficult for yourself.
Also, on how these methods are different. In the code I have written above, I have referenced three different functions. In the final one, where there is only one template parameter, the code generated for that function will include both code paths, when num == One
and when num == Two
. The first two templated methods, however, will have been able to remove those branches. It can do this because it will build two different code paths in memory, one for each case.