title: Is there a way to extract an object pointer from a std::function?
body: <p>I've got a class that holds a list of function objects (std::function).  Other classes can add functions to the list and these functions can be bound to member functions of that class.  This is all working fine.  However, I'd like to be able to distinguish when a function is from a different instance of the same class.  Is it possible to extract this information from the function object?</p>
  
  <p>In the code below, for example, in Foo::AddFunc() is it possible to extract the value of the object instance (i.e. b1 or b2) from the function object?</p>
  
  <pre><code>class Foo
  {
  public:
  
      typedef std::function&lt;void(int)&gt; Func;
  
      void AddFunc(const Func &amp;func)
      {
          // can i extract b1 or b2 here?
          m_funcs.push_back(func);
      }
  
      typedef std::vector&lt;Func&gt; Funcs;
      Funcs m_funcs;
  };
  
  Foo *g_foo = new Foo();
  
  class Bar
  {
  public:
  
      Bar()
      {
          Foo::Func func = std::bind(&amp;Bar::DoStuff, this, std::placeholders::_1);
          g_foo-&gt;AddFunc(func);
      }
  
      void DoStuff(int x)
      {
      }
  };
  
  ...
  
  Bar *b1 = new Bar();
  Bar *b2 = new Bar();
  </code></pre>