Well, in theory, C++0x Variadic Templates are precisely what you need to solve the above problem. Unfortunately, I don't believe any current compilers yet support them.