title: How to detect that instance passed to std::bind has destroyed
body: <p>I have a singleton that contains a list of <code>std::function</code> and periodically calls that.</p>
  <pre><code>class MySingleton
  {
  public:
      static MySingleton &amp;instance()
      {
          static MySingleton inst;
          return inst;
      }
  
      void addFunc(const std::function&lt;void(void)&gt; &amp;func)
      {
          m_list.push_back(func);
      }
  
  protected:
      void periodicallyCalled()
      {
          for(auto f: m_list)
          {
              f();
          }
      }
  
  private:
      std::vector&lt;std::function&lt;void(void)&gt;&gt; m_list;
  }
  </code></pre>
  <p>usage:</p>
  <pre><code>class Test
  {
  public:
      void test()
      {
          somenum ++;
      }
  protected:
      int somenum = 0;
  }
  
  
  Test *inst1 = new Test;
  auto f1 = std::bind(&amp;Test::test, inst1, std::placeholders::_1);
  MySingleton::instance().addFunc(f1);
  
  Test *inst2 = new Test;
  auto f2 = std::bind(&amp;Test::test, inst2, std::placeholders::_1);
  MySingleton::instance().addFunc(f2);
  </code></pre>
  <p>after a while I destroy one of objects:</p>
  <pre><code>delete inst1;
  </code></pre>
  <p>and <code>periodicallyCalled()</code> will crash since instance one of <code>std::function</code>s points on doesn't exist.</p>
  <p>So  my question - is there some way to prevent that? How can I detect that instance was deleted and I can safety remove such <code>std::function</code> from the list?</p>