I'm attempting to make a template function that takes a function as a parameter and the parameter function has arguments for the template to deduce.
Example time:
Here is a function that accepts a fixed function type and works
void func_a(void(*func)(int)) {
func(1);
}
int main() {
auto f = [](int x) -> void { printf("%i\n", x); };
func_a(f);
return 0;
}
Here is what I want to do, expanding on the first example (this won't compile)
template <typename... T>
void func_b(void(*func)(T...)) {
func(1);
}
int main() {
auto f = [](int x) -> void { printf("%i\n", x); };
func_b(f); // neither of
func_b<int>(f); // these work
return 0;
}
Ideally I'd like func_b to accept both a regular function and a lambda function like func_a does, but with template magics.
Aucun commentaire:
Enregistrer un commentaire