Take the function T
instead of the pointer:
template<typename T, typename... Params> void fun(T f, Params... params) { f(params...); } int main() { fun([](auto a, auto b) {}, 2, 3); }
Thus, the compiler can choose which congestion is the right of the call on the call site, and not inside the +
operator. As the comment says, in the general case, there is no +
operator for universal lambdas.
Alternatively, you can disable the compiler from trying to infer Params
from a function pointer using an authentication alias, but I really do not recommend it . Anyway, here you go:
template<typename T> struct identity { using type = T; }; template<typename T> using identity_t = typename identity<T>::type; template<typename... Params> void fun(void(*f)(identity_t<Params>...), Params... params) { f(params...); } int main() {
source share