I'm trying to write a variadic template function that includes a loop that iterates over each type in the parameter pack. I'm using this to build up a tuple which I then apply on the callback function which determined the template types.
I thought I could do this using sizeof...(Args) as follows:
template <typename ...Args>
void addCallback(void* handle, std::string address, std::function<void(Args...)> callback)
{
return addMessageCallback(std::move(address), [callback](const ci::osc::Message& message) {
std::tuple<Args...> args;
for (size_t i = 0; i < sizeof...(Args); i++)
{
std::get<i>(args) = message.getArg<std::tuple_element_t<i, decltype(args)>(i);
}
std::apply(callback, std::move(args));
});
}
This doesn't compile because std::get<i>(args) requires i to be a compile time constant. However, all the information is available at compile time. Is there a way to make this work? I've thought about using a fold expression but
I'm using C++17.