I remember seing something like this being done:
template
class X : public ListOfTypenames {};
that is, X inherits from
As others already answered, variadic templates are part of the next standard, but can be emulated in current C++. One convenient tool for this is to use the Boost.MPL library. In your code, you write a single template parameter (let's name it "Typelist"), and the users of your template wrap the typelist in an MPL sequence. Example:
#include "YourType.h"
#include "FooBarAndBaz.h"
#include
YourType > FooBarBaz;
In the implementation of "YourType", you can access the elements in Typelist with various metafunctions. For example, at_c
is the N
th element of the list. As another example, the "X" class in your question could be written with inherit_linearly
as:
//Warning: Untested
namespace bmpl = boost::mpl;
template
class X : bmpl::inherit_linearly >::type
{
...
};