Im trying to create some tool to create a list of types based on combinations of other types.
Lets say we have three types
struct A{};
struct B{};
struct C{};
I want to get a list of tuples which has every possible combination of N types A,B or C.
For a N=2 case, this would be
std::tuple<A,A>
std::tuple<A,B>
std::tuple<A,C>
std::tuple<B,A>
std::tuple<B,B>
std::tuple<B,C>
std::tuple<C,A>
std::tuple<C,B>
std::tuple<C,C>
The idea is to create a tuple which holds a container for all those types, so I can later store any of those types inside the container list.
template <typename ...Combinations>
using CombinationList = std::tuple<std::vector<Combinations>...>;
I already have a mechanism to inserting a particupar element inside the container in which it fits, but I have no clue on how to create the combinatios.
On the comments people has suggestes using std::vector<Combination<std::variant<A,C,B>, std::variant<A,B,C>>>
. Althought this technically solve the problem, I prefer not to use it, as A, B C and has very different sizes and I dont want to visit the variants at runtime. Also, at some point I will need to upload the all the data in the containers in
std::tuple<std::vector<Combination>...>
to the GPU, so I cant use std::variant here.
How could I do this?
Thanks!
PD: This is related to this question Combination explosion of an enum value (729 combinations...) In that question I asked how I could generate easily the types that would go inside the container. Now I need to generate the containers .
std::variant
(en.cppreference.com/w/cpp/utility/variant) would be a lot less work. – Demeanstd::vector<std::tuple<std::variant<A, B, C>, std::variant<A, B, C>>>
? – Grommetstruct
that contains anA
, aB
, and aC
and just ignoring one of them, using whatever mechanism you use to select the tuple member you want? – Demean