Unverified Commit f323d182 authored by pfeatherstone's avatar pfeatherstone Committed by GitHub
Browse files

simplification using C++11 types (#2446)


Co-authored-by: default avatarpfeatherstone <peter@me>
parent d29a8fc0
...@@ -18,29 +18,6 @@ namespace dlib ...@@ -18,29 +18,6 @@ namespace dlib
namespace impl namespace impl
{ {
template <typename T> struct selector {};
template <typename T, typename U, typename V>
void call_prom_set_value(
T& prom,
U& fun,
selector<V>
)
{
prom.set_value(fun());
}
template <typename T, typename U>
void call_prom_set_value(
T& prom,
U& fun,
selector<void>
)
{
fun();
prom.set_value();
}
template <typename> struct result_of; template <typename> struct result_of;
#if (__cplusplus >= 201703L || \ #if (__cplusplus >= 201703L || \
...@@ -71,21 +48,11 @@ namespace dlib ...@@ -71,21 +48,11 @@ namespace dlib
Args&&... args Args&&... args
) )
{ {
auto prom = std::make_shared<std::promise<typename impl::result_of<Function(Args...)>::type>>(); using return_type = typename impl::result_of<Function(Args...)>::type;
std::future<typename impl::result_of<Function(Args...)>::type> ret = prom->get_future(); using task_type = std::packaged_task<return_type()>;
using bind_t = decltype(std::bind(std::forward<Function>(f), std::forward<Args>(args)...)); auto task = std::make_shared<task_type>(std::bind(std::forward<Function>(f), std::forward<Args>(args)...));
auto fun = std::make_shared<bind_t>(std::bind(std::forward<Function>(f), std::forward<Args>(args)...)); auto ret = task->get_future();
tp.add_task_by_value([fun, prom]() tp.add_task_by_value([task]() {(*task)();});
{
try
{
impl::call_prom_set_value(*prom, *fun, impl::selector<typename impl::result_of<Function(Args...)>::type>());
}
catch(...)
{
prom->set_exception(std::current_exception());
}
});
return ret; return ret;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment