I have C++ code that wraps an arbitrary lambda and returns the result of the lambda.
template <typename F>
auto wrapAndRun(F fn) -> decltype(F()) {
// foo();
auto result = fn();
// bar();
return result;
}
This works unless F
returns void
(error: variable has incomplete type 'void'
). I thought of using a ScopeGuard
to run bar
, but I don't want bar
to run if fn
throws. Any ideas?
P.S. I found out later there's a proposal to fix this inconsistency.