title: Using `std::function<void(...)>` to call non-void function
body: <p>A while ago I used <code>std::function</code> pretty much like this:</p>
  
  <pre><code>std::function&lt;void(int)&gt; func = [](int i) -&gt; int { return i; };
  </code></pre>
  
  <p>Basically, I did this because I wanted to store different function objects in a <code>std::function</code>, but I didn't want to restrict the return types of these functions. Since this seemed to work, I went with it. But I'm not convinced that it is safe to use, and I haven't been able to find any documentation on it. Does anyone know whether this usage is legitimate? Or more generally, what the rules are for the object which can safely be assigned to a <code>std::function</code>?</p>
  
  <h2>Edit</h2>
  
  <p>For clarification, the issue I'm concerned with is that the lambda function returns an <code>int</code>, while <code>func</code> is declared with return type <code>void</code>. I'm not sure if this is OK, especially once a call to <code>func()</code> is made.</p>