title: How to use a std::function as a C style callback
body: <p>How can I use a <code>std::function</code> in a function which expects a C-style callback?</p>
  
  <p>If this is not possible, what is the next best thing?</p>
  
  <p>Example:</p>
  
  <pre><code>// --- some C code I can not change ---
  typedef void(*fun)(int);
  void register_callback(fun f) {
      f(42); // a test
  }
  // ------------------------------------
  
  #include &lt;functional&gt;
  #include &lt;iostream&gt;
  
  void foo(const char* ptr, int v, float x) {
      std::cout &lt;&lt; ptr &lt;&lt; " " &lt;&lt; v &lt;&lt; " " &lt;&lt; x &lt;&lt; std::endl;
  }
  
  int main() {
      std::function&lt;void(int)&gt; myf = std::bind(&amp;foo, "test", std::placeholders::_1, 3.f);
      register_callback(myf); // &lt;-- How to do this?
  }
  </code></pre>