From 3c3676a864e7a1c8f3b9a250288a54456b0da0cd Mon Sep 17 00:00:00 2001 From: gconeice Date: Mon, 21 Oct 2024 16:58:33 -0400 Subject: [PATCH] [upgrade] ThreadPool now supports C++20 --- 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)...)