progschj / ThreadPool

A simple C++11 Thread Pool implementation
zlib License
7.86k stars 2.24k forks source link

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

Closed jared-schmitz closed 11 years ago

jared-schmitz commented 11 years ago

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.

progschj commented 11 years ago

Seems I never tried using member pointers with it. Using result_of looks way cleaner anyway. Nice!

ac2a77d5cc04361d341f63b1d19706a4d1b4943e

jared-schmitz commented 11 years ago

Looks like this is merged!