title: Performance of std::function compared to raw function pointer and void* this?
body: <p>Library code:</p>
  
  <pre><code>class Resource 
  {
  public:
      typedef void (*func_sig)(int, char, double, void*);
  //Registration
      registerCallback(void* app_obj, func_sig func)
      {
          _app_obj = app_obj;
          _func = func;
      }
  
  //Calling when the time comes
      void call_app_code()
      {
          _func(231,'a',432.4234,app_obj);
      }
  //Other useful methods
  private:
      void* app_obj;
      func_sig _func;
  //Other members
  };
  </code></pre>
  
  <p>Application Code:</p>
  
  <pre><code>class App
  {
  public:
      void callme(int, char, double);
  //other functions, members;
  };
  
  void callHelper(int i, char c, double d, void* app_obj)
  {
      static_cast&lt;App*&gt;(app_obj)-&gt;callme(i,c,d);
  }
  
  int main()
  {
      App a;
      Resource r;
      r.registercallback(&amp;a, callHelper);
  //Do something
  }
  </code></pre>
  
  <p>The above is a minimal implementation of callback mechanism. It is more verbose, doesn't support binding, placeholders etc., like std::function.
  If I use a <code>std::function</code> or <code>boost::function</code> for the above usecase, will there be any performance drawbacks? This callback is going to be in the very very critical path of a real time application. I heard that boost::function uses virtual functions to do the actual dispatch. Will that be optimized out if there are no binding/placeholders involved?</p>
  
  <p><strong>Update</strong></p>
  
  <p>For those interested in inspecting the assemblies in latest compilers: <a href="https://gcc.godbolt.org/z/-6mQvt" rel="nofollow noreferrer">https://gcc.godbolt.org/z/-6mQvt</a></p>