diff --git a/src/threadpool.h b/src/threadpool.h index 51e5d6e134..57c21b2e16 100644 --- a/src/threadpool.h +++ b/src/threadpool.h @@ -35,13 +35,24 @@ #include #include +// compatibility with C++17 deprecation of result_of +#if __cplusplus >= 201703L +// std::invoke_result_t should be used from C++17 onwards, but is not available in C++14 and earlier +template +using threadpool_result_t = std::invoke_result_t; +#else +// std::result_of should be used on C++14 and earlier, but is deprecated in C++17 +template +using threadpool_result_t = typename std::result_of::type; +#endif + class CThreadPool { public: CThreadPool() = default; CThreadPool ( size_t ); template - auto enqueue ( F&& f, Args&&... args ) -> std::future::type>; + auto enqueue ( F&& f, Args&&... args ) -> std::future>; ~CThreadPool(); private: @@ -87,9 +98,9 @@ inline CThreadPool::CThreadPool ( size_t threads ) : stop ( false ) // add new work item to the pool template -auto CThreadPool::enqueue ( F&& f, Args&&... args ) -> std::future::type> +auto CThreadPool::enqueue ( F&& f, Args&&... args ) -> std::future> { - using return_type = typename std::result_of::type; + using return_type = threadpool_result_t; auto task = std::make_shared> ( std::bind ( std::forward ( f ), std::forward ( args )... ) );