Given the following function:
template<class F, class... Args>
auto ThreadPool::enqueue(F&& f, Args&&... args)
-> std::future<typename std::result_of<F(Args...)>::type>
{
using return_type = typename std::result_of<F(Args...)>::type;
auto task = std::make_shared< std::packaged_task<return_type()> >(
std::bind(std::forward<F>(f), std::forward<Args>(args)...)
);
std::future<return_type> res = task->get_future();
return res;
}
What's the right way to pass a member function to ThreadPool::enqueue as parameter, say the object is:
Foo foo
and the function is:
foo.do_something();
I have tried to use std::bind and std::mem_fn with or without "&" and all failed.
pool.enqueue([foo]() { foo.do_something(); });pool.enqueue(&Foo::do_something, &foo, other_args_to_do_something...).