How to (or is it possible to) unpack a parameter pack with a numeric sequence? For example,
template <typename C, typename... T>
C* init_from_tuple(bp::tuple tpl)
{
return new C{bp::extract<T>("magic"(tpl))...}; // <--
}
which the <-- line should expand to
return new C{bp::extract<T0>(tpl[0]),
bp::extract<T1>(tpl[1]),
.....
bp::extract<Tn>(tpl[n])};
where n == sizeof...(T) - 1.
The purpose is to create a __init__ function for Boost.Python which accepts a tuple with predefined types.
Actually, it is possible for the unpack operations to target two different packs of parameters at once (I think they need be of equal length). Here we would like a pack of types, and a pack of numbers.
Something akin to:
We “just” need to generate the pack of indices:
And then use it:
In action at Ideone.
We can witness the correctness by making a “mistake” in the implementation of
init_from_tuple_impl(remove thenewfor example):In action at Ideone:
Exactly what we wanted 🙂