title: self-destroy std::function during call
body: <p>I have class implementing callbacks using std::function template. I recently noticed, that I destroy the object inside callback (i.e. std::function destroys itself). </p>
  
  <p>Is it a well-known issue? Does std::function designers foresaw that it may happen (is std::function resilient to such situations)?</p>
  
  <p>Sample code:</p>
  
  <pre><code>struct Sample
  {
      std::function&lt;void()&gt; callback;
  
      void emit_callback ()
      {
          callback ();
      }
  }
  
  void callback(Sample* object)
  {
      delete object;
  }
  
  /////////////////////////////////////////////
  
  Sample* object = new Sample();
  object-&gt;callback = std::bind(&amp;callback, object);
  object-&gt;emit_callback ();
  </code></pre>