I have some classes all having a constructor that takes a file path. I would like to create a std::tuple of them from the argv argument in the main function. Here is a sketch
class A {
public:
A(const char *); // Taking a file path
};
class B {
public:
B(const char *); // Taking a file path
};
int main(int argc, char* argv[]) {
auto tup(myCreateTuple<A, B, A>(argc, argv));
// myCreateTuple would in this case use argv[1], argv[2]
// and argv[3] to create A(argv[1]), B(argv[2]) and A(argv[3]).
// argc is just passed along to verify that argv is long enough.
// tup would have of the type std::tuple<A ,B, A>
}
The order in which the tuple members are created is not important (i.e. the execution order of the constructors is allowed to be undefined). Do you have an idea of how to implement myCreateTuple?
I guess it would be possible to avoid myCreateTuple all together and instead use
std::tuple<A, B, A> tup{ A(argv[1]), B(argv[2]), A(argv[3]) };
but that would be a less generic solution.
Using
<redi/index_tuple.h>to provide a compile-time integer sequence that produces the array indices in a pack expansion: