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 <
With Boost.Mp11, this is a short one-liner (as always):
using input = type_list;
using result = mp_product<
type_pair,
input, input>;
Demo.
We can generalize this to picking N things, with repetition, from that input. We can't use type_pair anymore to group our elements, so we'll just have a list of type_list of elements. To do that, we basically need to write:
mp_product
// ~~~~~~~ N times ~~~~~~~~
Which is also the same as:
mp_product_q, input, input, ..., input>
// ~~~~~~~ N times ~~~~~~~~
One way to do that is:
template
using product = mp_apply<
mp_product_q,
mp_append<
mp_list>,
mp_repeat_c, N>
>>;
Demo.