Skip to content

Commit

Permalink
#2027: runnable: clever workaround to avoid branching on return type
Browse files Browse the repository at this point in the history
  • Loading branch information
lifflander committed Feb 8, 2023
1 parent 703a972 commit 8820ec9
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/vt/runnable/make_runnable.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,10 @@ struct RunnableMaker {
template <typename Callable, typename... Args>
auto runLambda(Callable&& c, Args&&... args) {
setup();
if constexpr(std::is_void_v<std::invoke_result_t<Callable, Args...>>) {
std::invoke(std::forward<Callable>(c), std::forward<Args>(args)...);
delete impl_;
impl_ = nullptr;
is_done_ = true;
} else {
decltype(auto) r{impl_->runLambda(std::forward<Callable>(c), std::forward<Args>(args)...)};
delete impl_;
impl_ = nullptr;
is_done_ = true;
return r;
}
auto local_impl = std::unique_ptr<RunnableNew>(impl_);
impl_ = nullptr;
is_done_ = true;
return local_impl->runLambda(std::forward<Callable>(c), std::forward<Args>(args)...);
}

/**
Expand Down

0 comments on commit 8820ec9

Please sign in to comment.