progschj / ThreadPool

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

enqueue: provide variadic function #6

Closed daniel-j-h closed 11 years ago

daniel-j-h commented 11 years ago

For now we're able to enqueue e.g. lambdas, or use std::bind to curry functions taking various arguments.

It would be reasonable to provide a variadic enqueue instead, taking various arguments and simply passing them on, e.g.

template<typename Function, typename... Args>
auto enqueue(Function&& f, Args&&... args) -> std::future<decltype(std::forward<F>(f)(std::forward<Args>(args)...))>;

The behavior should be similar to e.g. std::thread's interface.

progschj commented 11 years ago

I tried adding this in the develop branch. But since packaged_task doesn't actually package arguments I ended up using bind internally anyway. There may be a better way I don't know about though.