The VC++ 2013 compiler supports variadic templates. They are templates that can take a variable number of template arguments. In my opinion, it’s more a feature for library authors than for library consumers, so I am not sure how popular its use will be among end-user C++ developers. Here’s a very simple example that shows variadic templates in action.
// Variadic template declaration
template<typename... Args> class Test;
// Specialization 1
template<typename T> class Test<T>
{
public:
T Data;
};
// Specialization 2
template<typename T1, typename T2> class Test<T1, T2>
{
public:
T1 Left;
T2 Right;
};
void Foo()
{
Test<int> data;
data.Data = 24;
Test<int, int> twovalues;
twovalues.Left = 12;
twovalues.Right = 15;
}
The intellisense kicks in and works beautifully too when using variadic templates. I will be trying to blog more on the use of variadic templates in the near future.