I have a function foo
that takes a variadic function pointer as its argument.
I would like to use "using" to define the argument's type prior to the function declaration.
template <typename ... vARGS>
using TFuncType = void(*)(vARGS ... V_args);
template <typename ... vARGS>
void foo(TFuncType<vARGS ...> funcptr) {}
void bar(int i) {}
int main() {
foo(&bar); // This line fails to compile.
}
This doesn't compile. The error (via clang using c++1z) is:
/make/proj/test/variadic-funcparam-deduce2.cpp:39:5: error: no matching function for call to 'foo'
foo(&bar);
^~~
/make/proj/test/variadic-funcparam-deduce2.cpp:33:36: note: candidate template ignored: substitution failure [with vARGS = int]
template <typename ... vARGS> void foo(TFuncType<vARGS ...> funcptr) {}
Why is the "int" substitution failing?
I can successfully compile if I explicitly write the type inside foo():
template <typename ... vARGS>
void foo(void(*funcptr)(vARGS ... V_args)) {}
But I cannot get the initial ("using") version to work even when explicitly specifying the template parameters, and using a pre-casted TFuncType<int>
for the argument, i.e.:
int main() {
TF_call<int> fptr = &bar; // This line is OK.
foo<int>(fptr);
}
Does anyone know what's up here?
Is there something strange about using typedef'd ("using") variadics and/or function pointers that I'm missing?