From 26e789764cb2bad458e59961716a99ab97eb0688 Mon Sep 17 00:00:00 2001 From: eason Date: Fri, 24 May 2024 17:09:03 +0800 Subject: [PATCH] Use rvalue reference and make the lambda expression more instinctive --- ThreadPool.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ThreadPool.h b/ThreadPool.h index 4183203..e2b72d5 100644 --- a/ThreadPool.h +++ b/ThreadPool.h @@ -16,7 +16,7 @@ class ThreadPool { ThreadPool(size_t); template auto enqueue(F&& f, Args&&... args) - -> std::future::type>; + -> std::future::type>; ~ThreadPool(); private: // need to keep track of threads so we can join them @@ -61,7 +61,7 @@ inline ThreadPool::ThreadPool(size_t threads) // add new work item to the pool template auto ThreadPool::enqueue(F&& f, Args&&... args) - -> std::future::type> + -> std::future::type> { using return_type = typename std::result_of::type; @@ -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;