I am aware that functions can be template arguments. However GCC, Clang and MSVC (compile versions on rextester) do not compile compile when the template is variadic, as shown below:
void Func( int ){}
template<void (*)(int)>
struct Foo{};
template struct Foo<Func>; // Compiles
template<typename>
struct Bar;
template<typename ...Args>
struct Bar<void(*)(Args...)>
{
};
template struct Bar<Func>; // Does NOT compile (why???)
int main()
{
}
MSVC produces the most verbose output and possible explanation (rightly or wrongly) as to why the code does not compile.
source_file.cpp(20): error C2923: 'Bar': 'Func' is not a valid template type argument for parameter 'T'
source_file.cpp(1): note: see declaration of 'Func'
source_file.cpp(20): error C2990: 'Bar': non-class template has already been declared as a class template
source_file.cpp(13): note: see declaration of 'Bar'
source_file.cpp(20): error C2946: explicit instantiation; 'Bar' is not a template-class specialization
What is the appropriate syntax for passing functions that accept any number of arguments themselves as class template arguments.