-
-
Save rightfold/f3bc2ad2dc32297923f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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