I'm trying to use templates in C++ to do the following:
I have a function like this:
template<typename... Args>
void f1(const std::tuple<Args...>& t1);
Inside this function, I would like to create another tuple t2 such that every elements of t1 is copied into t2 at the same position, except for elements of type A, for which t2 should create an object of type B.
However, the constructor of B
takes a reference to an object of type A
as well as a second argument of type C&
. An instance of C
is created before the conversion and should be passed as second argument to the constructor of B
whenever an object of type A
is encountered.
Something like this, only completely generalized:
std::tuple<int, B, double, B> Convert(std::tuple<int, A, double, A> tpl, C& c)
{
return std::tuple<int, B, double, B>(
std::get<0>(tpl),
B(std::get<1>(tpl), c),
std::get<2>(tpl),
B(std::get<3>(tpl), c),
);
}