I have a template function taking a std::function parameter, the template arguments defining function signature:
template<typename... Args>
void addController(const char * name, const std::function<bool(Args...)> & func);
It works passing a std::function variable:
std::function<bool()> foo_func = [this]()->bool {return this->isFoo(); };
addController<>("foo", foo_func); //Works
But if I pass the lambda directly, it fails deducing the type:
//Fails to compile
addController<>("foo", [this]()->bool {return this->isFoo(); });
And using a non template function works:
void addControllerNoArg(const char * name, std::function<bool()> func);
addControllerNoArg("foo", [this]() {return this->isFoo(); }); //Works
I need the <typename... Args> template for unwrapping a variant vector argument tables into the function call. This actually does work in the implementation, the only issue is I can't pass a lambda to addController directly.
Minimal example: https://onlinegdb.com/MS1cEreKhk
template <typename FunctionType> void addControler(F f);. Don't confusestd::functionto be the goto type whenever you need to pass around a callable. You need it for type erasure, ie when you need one object that can store all kinds of callables#includesand the context forthisis a lot, when someone else wants to either reproduce your error or test their answer.