From 88f722f64e7ccb2546afe8b4d7a3f043ed2f6b42 Mon Sep 17 00:00:00 2001 From: Yibin Yang Date: Mon, 21 Oct 2024 17:26:03 -0400 Subject: [PATCH] [upgrade] ThreadPool now supports C++20 (#195) --- emp-tool/utils/ThreadPool.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/emp-tool/utils/ThreadPool.h b/emp-tool/utils/ThreadPool.h index 19c7bc1..83143a5 100644 --- a/emp-tool/utils/ThreadPool.h +++ b/emp-tool/utils/ThreadPool.h @@ -39,8 +39,13 @@ class ThreadPool { public: ThreadPool(size_t); template +#if __cplusplus >= 202002L + auto enqueue(F&& f, Args&&... args) + -> std::future::type>; +#else auto enqueue(F&& f, Args&&... args) -> std::future::type>; +#endif ~ThreadPool(); int size() const; private: @@ -87,11 +92,19 @@ inline ThreadPool::ThreadPool(size_t threads) } // add new work item to the pool +#if __cplusplus >= 202002L +template +auto ThreadPool::enqueue(F&& f, Args&&... args) + -> std::future::type> +{ + using return_type = typename std::invoke_result::type; +#else template auto ThreadPool::enqueue(F&& f, Args&&... args) -> std::future::type> { using return_type = typename std::result_of::type; +#endif auto task = std::make_shared< std::packaged_task >( std::bind(std::forward(f), std::forward(args)...)