From 737db8ec259395505d35757037169828cfe1e5a2 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Mon, 4 Jan 2016 13:02:30 +0100 Subject: [PATCH] [simix] Fix simgrid::simix::kernel for void return --- include/simgrid/simix.hpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/include/simgrid/simix.hpp b/include/simgrid/simix.hpp index 5fbc4d5fd8..0cdf6ea490 100644 --- a/include/simgrid/simix.hpp +++ b/include/simgrid/simix.hpp @@ -24,18 +24,38 @@ XBT_PUBLIC(void) simcall_run_kernel(std::function const& code); namespace simgrid { namespace simix { +template +void fulfill_promise(std::promise& promise, F&& code) +{ + try { + promise.set_value(code()); + } + catch(...) { + promise.set_exception(std::current_exception()); + } +} + +// special version for R=void because the previous code does not compile +// in this case: +template +void fulfill_promise(std::promise& promise, F&& code) +{ + try { + code(); + promise.set_value(); + } + catch(...) { + promise.set_exception(std::current_exception()); + } +} + template typename std::result_of::type kernel(F&& code) { typedef typename std::result_of::type R; std::promise promise; simcall_run_kernel([&]{ - try { - promise.set_value(code()); - } - catch(...) { - promise.set_exception(std::current_exception()); - } + fulfill_promise(promise, code); }); return promise.get_future().get(); } -- 2.20.1