I have the following class which contains a lambda member variable:
template <typename Callable>
class task {
private:
Callable lambda;
public:
task(Callable l) : lambda(l) {}
void execute() {
lambda();
}
};
Now I want to create a function which accepts a object of any class and a member function pointer of that class, then creates lambda, creates a task from that lambda and finally returns the task. But I can't figure out the return type of the function:
template <typename C, typename F, typename ...Args>
/* return type ?*/ create_task(C& obj, F func, Args... args) {
auto l = [&obj, func, args...] {
(obj.*func)(args...);
};
task<decltype(l)> t {l};
return t;
}
How can this be done in C++11
? I'm also open for other suggestions, BUT they'll have to do without dynamic memory allocation.