I have the following code:
#include <iostream>
#include <functional>
template<typename Return, typename... Params>
void func(std::function<Return(Params... )> x) {}
void f(double) {}
int main() {
//func<void, double>(f); // compile error here in the variadic case
func(std::function<void(double)>(f));
}
I have 2 questions:
1.
I do not understand why does the line func<void, double>(f);
give me a compiling error
/Users/vlad/minimal.cpp:10:5: error: no matching function for call to 'func'
func<void, double>(f); // compile error here in the variadic case
^~~~~~~~~~~~~~~~~~
/Users/vlad/minimal.cpp:5:6: note: candidate template ignored: could not match 'function<void (double, type-parameter-0-1...)>' against 'void (*)(double)'
void func(std::function<Return(Params... )> x) {}
^
1 error generated.
whereas if I cast the parameter f
to a std::function
(as in the non-commented line) it works.
2.
And the most puzzling issue is that, if I use a non-variadic version of func
(i.e. just replace typename...
by typename
so in effect func
takes a std::function<Return(Params)>
as parameter), then the commented line in main
works as desired. Any ideas why?