I have a little class for callback with parameter
template<typename Ret, typename ...Args>
class Callback
{
public:
typedef Ret (*Ptr)(Args..., void* param);
Ptr m_func;
void* m_param;
void setFunc(void* func) { m_func = (Ptr)func; }
template<typename T>
void setFunc(const T& func) { m_func = (Ptr)func; }
};
"param" member is a void pointer, but it actually may point to different structs even in context of one callback So I can use setFunc with simple function like this:
void func1(..., ExampleContext* param) { ... }
callback.setFunc(func1);
But with non-capturing lambda I can only use it with strict void type:
callback.setFunc([](..., void* param) { ... });
I can convert lambda to its pointer, but I should write its typedef and cast, while I want setFunc to accept lambdas with any param type without additional conversions outside of Callback class, can I do it somehow? Thank you.
funcandparambothstd::function<Ret(Args...)>? The user can pass custom callback data withstd::bind. - KamilCuk