I\'d like to create the cross product of a list of types using variadic templates.
Here\'s what I have so far:
#include
#include <
Maybe something like this:
template struct typelist { };
template struct typelist_cat;
template
struct typelist_cat, typelist>
{
typedef typelist type;
};
template struct product;
template
struct product, typelist>
{
// the cartesian product of {S} and {Ts...}
// is a list of pairs -- here: a typelist of 2-element typelists
typedef typelist...> S_cross_Ts;
// the cartesian product of {Ss...} and {Ts...} (computed recursively)
typedef typename product, typelist>::type
Ss_cross_Ts;
// concatenate both products
typedef typename typelist_cat::type type;
};
// end the recursion
template
struct product, typelist>
{
typedef typelist<> type;
};
Now you should be able to use product
.