title: Handling void assignment in C++ generic programming
body: <p>I have C++ code that wraps an arbitrary lambda and returns the result of the lambda.</p>
  <pre><code>template &lt;typename F&gt;
  auto wrapAndRun(F fn) -&gt; decltype(F()) {
      // foo();
      auto result = fn();
      // bar();
      return result;
  }
  </code></pre>
  <p>This works unless <code>F</code> returns <code>void</code> (<code>error: variable has incomplete type 'void'</code>). I thought of using a <code>ScopeGuard</code> to run <code>bar</code>, but I don't want <code>bar</code> to run if <code>fn</code> throws. Any ideas?</p>
  <p>P.S. I found out later there's <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0146r1.html" rel="nofollow noreferrer">a proposal to fix this inconsistency</a>.</p>