https://gist.github.com/i6o6i/4d588435cd25c1a47fcea1eab796f807
what are you trying to do here?
std::promise<std::result_of<F(Args...)>> p;
queue.push_back(bind(p,f,args...));
cv_jobsadd.notify_one();
return p.get_future();
Your call to std::bind doesn't seem right, the first parameter is the callable object and all the following parameters are the parameters passed to the callable.
Does this (requires c++17) do what you want? Create a std::function<void()> that calls the passed callable with the required args and after this callable returns sets the value of the promise.
template<class F, class ...Args>
std::future<
typename std::result_of<F(Args...)>::type
>
ThreadPool::emplace_back(
F&& f,
Args&&... args)
{
using RetType = typename std::result_of<F(Args...)>::type;
std::promise<RetType> p;
queue.push_back([&](){
if constexpr (std::is_same<void, RetType>::value) {
std::forward<F>(f)(std::forward<Args>(args)...);
p.set_value();
} else {
p.set_value(std::forward<F>(f)(std::forward<Args>(args)...));
}
});
cv_jobsadd.notify_one();
return p.get_future();
}