Skip to content

Commit

Permalink
return type deduction now with result_of
Browse files Browse the repository at this point in the history
as suggested by https://github.com/n00btime
return type deduction now uses std::result_of
which allows return type deduction for pointer
to members (and looks cleaner anyway).
  • Loading branch information
progschj committed May 22, 2013
1 parent e398e2d commit ac2a77d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ThreadPool {
ThreadPool(size_t);
template<class F, class... Args>
auto enqueue(F&& f, Args&&... args)
-> std::future<decltype(std::forward<F>(f)(std::forward<Args>(args)...))>;
-> std::future<typename std::result_of<F(Args...)>::type>;
~ThreadPool();
private:
// need to keep track of threads so we can join them
Expand All @@ -35,7 +35,7 @@ inline ThreadPool::ThreadPool(size_t threads)
: stop(false)
{
for(size_t i = 0;i<threads;++i)
workers.push_back(std::thread(
workers.emplace_back(
[this]
{
while(true)
Expand All @@ -51,15 +51,15 @@ inline ThreadPool::ThreadPool(size_t threads)
task();
}
}
));
);
}

// add new work item to the pool
template<class F, class... Args>
auto ThreadPool::enqueue(F&& f, Args&&... args)
-> std::future<decltype(std::forward<F>(f)(std::forward<Args>(args)...))>
-> std::future<typename std::result_of<F(Args...)>::type>
{
typedef decltype(std::forward<F>(f)(std::forward<Args>(args)...)) return_type;
typedef typename std::result_of<F(Args...)>::type return_type;

// don't allow enqueueing after stopping the pool
if(stop)
Expand Down

0 comments on commit ac2a77d

Please sign in to comment.