samedi 6 juin 2020

Passing member function to Template function

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();

What's the right way to pass a member function to enqueue as parameter, say the object is:

Foo foo

and the function is:

foo.do_something();

I have tried to use bind and mem_fen with or without "&" and all failed.

Aucun commentaire:

Enregistrer un commentaire