So I have a variable argument function with different argument types; I would like to pass every argument to another function which is a C function. As an example; for a case with two arguments;
void function(int *a, double *b) needs to call
{
bindToFunc(0, a);
bindToFunc(1, b);
}
void function(int *a, double *b, float *c) needs to call
{
bindToFunc(0, a);
bindToFunc(1, b);
bindToFunc(2, c);
}
template<typename... T>
void function(T ...)
{
// has to have
//
// bindToFunc(0, T0) ....
// bindToFunc(n-1, Tn-1);
}
I tried using,
template <int I, class... Ts>
decltype(auto) get(Ts &&... ts)
{
return std::get<I>(std::forward_as_tuple(ts...));
}
but since I is the template parameter, it is a compile time variable and hence we can not use it in with a for loop.
With C++17 and fold expression, you might do:
template<typename... Ts>
void function(Ts... args)
{
[[maybe_unused]] int i = 0; // Not used for empty pack.
(bindToFunc(i++, args), ...);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With