Skip to content

Template deduction fails with pointer-to-member functions #8

@jared-schmitz

Description

@jared-schmitz

Code such as this will fail in template deduction:

auto member_task = TP.enqueue(&MyClass::member_func, this);

std::result_of uses std::declval to get the proper result.

Changing the declaration of ThreadPool::enqueue to:

template <class F, class... Args>
auto enqueue(F&& f, Args&&... args) 
    -> std::future<typename std::result_of<F(Args...)>::type>;

allows the above to compile. Similarly change the typedef inside the definition.

If I felt I had more expertise in template metaprogramming, I would have submitted a patch. But I may have omitted std::forward in places where it matters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions