Templates are one of the most powerful features in C++, and variadic templates make them even more powerful. Variadic templates in the C++0x standard library can greatly simplify the writing of type-safe code with variable numbers of arguments.
by Anthony Williams
April 24, 2009
f you've been programming in C++ for any time at all then you're familiar with variadic functions, functions (such as printf) that can take a variable number of arguments. C99 introduced variadic macros, which also take a variable number of arguments. C++0x takes this concept a step further with the introduction of variadic templates, where the number of template arguments is not specified when you write the template.
You declare the variadic part of a variadic template with an ellipsis (...) just like with a variadic function, though in this case it goes in the template parameter list:
template<typename ... Args>
class my_class
{};
It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com. Already a member?
To become a member of DevX.com create your Member Profile by completing the form below. Membership is free!