Skip to content

Commit

Permalink
Merge pull request #121 from xthexder/xthexder/master
Browse files Browse the repository at this point in the history
Use std::invoke_result instead of std::result_of to support C++20
  • Loading branch information
jratcliff63367 authored Jul 27, 2022
2 parents f623c29 + 53f32ae commit 7677ae5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion include/VHACD.h
Original file line number Diff line number Diff line change
Expand Up @@ -6306,7 +6306,11 @@ class ThreadPool {
~ThreadPool();
template<typename F, typename... Args>
auto enqueue(F&& f, Args&& ... args)
#ifndef __cpp_lib_is_invocable
-> std::future< typename std::result_of< F( Args... ) >::type>;
#else
-> std::future< typename std::invoke_result_t<F, Args...>>;
#endif
private:
std::vector<std::thread> workers;
std::deque<std::function<void()>> tasks;
Expand Down Expand Up @@ -6350,10 +6354,18 @@ ThreadPool::ThreadPool(int worker) : closed(false), count(0)

template<typename F, typename... Args>
auto ThreadPool::enqueue(F&& f, Args&& ... args)
#ifndef __cpp_lib_is_invocable
-> std::future< typename std::result_of< F( Args... ) >::type>
#else
-> std::future< typename std::invoke_result_t<F, Args...>>
#endif
{

using return_type = typename std::result_of< F( Args...) >::type;
#ifndef __cpp_lib_is_invocable
using return_type = typename std::result_of< F( Args... ) >::type;
#else
using return_type = typename std::invoke_result_t< F, Args... >;
#endif
auto task = std::make_shared<std::packaged_task<return_type()> > (
std::bind(std::forward<F>(f), std::forward<Args>(args)...)
);
Expand Down

0 comments on commit 7677ae5

Please sign in to comment.