Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jared-schmitz opened this issue May 21, 2013 · 2 comments
Closed

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

jared-schmitz opened this issue May 21, 2013 · 2 comments

Comments

@jared-schmitz
Copy link

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
Copy link
Owner

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

ac2a77d

@jared-schmitz
Copy link
Author

Looks like this is merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants