I was trying to write a function to forward arguments for a variadic template function, similar to std::invoke
. Here is the code:
#include <functional>
template<class... Args>
void f(Args&&... args) { }
template<template<class...> class F, class... Args>
void invoke(F<Args...> f, Args&&... args) {
f(std::forward<decltype(args)>(args)...);
}
int main() {
invoke(f, 1, 2, 3);
std::invoke(f, 1, 2, 3);
}
However, both my invoke
and std::invoke
fails to compile.
g++ complains that it couldn't deduce template parameter template<class ...> class F
. So is it possible to invoke a variadic template function without explicit template specialization?