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

Use rvalue reference and make the lambda expression more instinctive #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 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<typename std::result_of<F(Args...)>::type>;
-> std::future<typename std::result_of<F(Args&&...)>::type>;
~ThreadPool();
private:
// need to keep track of threads so we can join them
Expand Down Expand Up @@ -61,7 +61,7 @@ inline ThreadPool::ThreadPool(size_t threads)
// add new work item to the pool
template<class F, class... Args>
auto ThreadPool::enqueue(F&& f, Args&&... args)
-> std::future<typename std::result_of<F(Args...)>::type>
-> std::future<typename std::result_of<F(Args&&...)>::type>
{
using return_type = typename std::result_of<F(Args...)>::type;

Expand All @@ -77,7 +77,7 @@ auto ThreadPool::enqueue(F&& f, Args&&... args)
if(stop)
throw std::runtime_error("enqueue on stopped ThreadPool");

tasks.emplace([task](){ (*task)(); });
tasks.emplace([task](){ return (*task)(); });
}
condition.notify_one();
return res;
Expand Down