I have a few classes:
template <int,char>
class Foo{};
template <int,char>
class Bar{};
And I want to get all combinations with a few arguments, like this:
// {1, 2}, {'a', 'b'}
using CartesianProduct = mp_list<Foo<1,'a'>, Foo<1,'b'>,...,Bar<2,'b'>>;
I can change template parameters to types and use std::integral_constant, if it cannot be done with numeric constants.
I found a similar question, but it's far more difficult. Creating all template permutations with MPL. I assume, there is a better and easier solution for my case.
Finally, I figured it out by myself.
Result:
It uses
std::integral_constantfor arguments, but it's simple and short. Try it hereUPD: And I found how to use integers itselfs!
Result:
Try it here!
UPD2: Only clang can compile this code. It seems like there is a bug in msvc and gcc, because clang can build this code even with
-pedantic-errorsUPD3: Now gcc also can compile it