title: How to properly check if std::function is empty in C++11?
body: <p>I was wondering how to properly check if an <code>std::function</code> is empty. Consider this example:</p>
  
  <pre><code>class Test {
      std::function&lt;void(int a)&gt; eventFunc;
  
      void registerEvent(std::function&lt;void(int a)&gt; e) {
          eventFunc = e;
      }
  
      void doSomething() {
          ...
          eventFunc(42);
      }
  };
  </code></pre>
  
  <p>This code compiles just fine in MSVC but if I call <code>doSomething()</code> without initializing the <code>eventFunc</code> the code obviously crashes. That's expected but I was wondering what is the value of the <code>eventFunc</code>? The debugger says <code>'empty'</code>. So I fixed that using simple if statement:</p>
  
  <pre><code>   void doSomething() {
          ...
          if (eventFunc) {
              eventFunc(42);
          }
     }
  </code></pre>
  
  <p>This works but I am still wondering what is the value of non-initialized <code>std::function</code>? I would like to write <code>if (eventFunc != nullptr)</code> but <code>std::function</code> is (obviously) not a pointer.</p>
  
  <p>Why the pure if works? What's the magic behind it? And, is it the correct way how to check it?</p>