From: Gabriel Corona Date: Mon, 4 Jan 2016 12:02:30 +0000 (+0100) Subject: [simix] Fix simgrid::simix::kernel for void return X-Git-Tag: v3_13~1359 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/737db8ec259395505d35757037169828cfe1e5a2 [simix] Fix simgrid::simix::kernel for void return --- 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(); }