Generating objects of variable types from combinations of constructor arguments

Viewed 301

Suppose I have types A, B with constructors A(int a, double b, std::string c), B(double a, int b).

I know how to define a function that instantiates either A or B via variadic templates.

Is there any way to design a function/macro/type that for a type T and a series of vectors of possibilities for T's constructor arguments it provides me with all possible objects?

For example, if I use this magical construct for <A, {2, 5, 6}, {2.44, 3.14}, {"yes", "no"}> it should provide the objects:

A(2, 2.44, "yes")
A(2, 2.44, "no")
A(2, 3.14, "yes")
...
A(6, 3.14, "no")

The same should work for B or any other type without having to rework the magical construct.

This is super easy in Python for example, but I don't know if it's possible in C++.

6 Answers
Related