Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active August 29, 2015 14:18
Show Gist options
  • Save rightfold/f3bc2ad2dc32297923f0 to your computer and use it in GitHub Desktop.
Save rightfold/f3bc2ad2dc32297923f0 to your computer and use it in GitHub Desktop.
template<typename R>
struct call_with_proper_order_of_evaluation {
template<typename F, typename... Args>
call_with_proper_order_of_evaluation(F&& f, Args&&... args)
: result(std::forward<F>(f)(std::forward<Args>(args)...)) { }
R result;
};
template<typename... Args, typename F>
handle make_subroutine(F impl) {
return handle(subroutine([impl = std::move(impl)] (auto arguments_begin, auto arguments_end) {
if (static_cast<std::size_t>(std::distance(arguments_begin, arguments_end)) != sizeof...(Args)) {
throw precondition_violation("invalid number of arguments passed");
}
call_with_proper_order_of_evaluation<handle> call{impl, arguments_begin++->template data<Args>()...};
return call.result;
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment