title: Unit test whether a function object gets called
body: <p>Mocks are used to detect function calls. What can be done if we have a class with a function object:</p>
  
  <pre><code>#include &lt;functional&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  class A {
      public:
          A(){};
          void doit(){
              //...
              if(f)
                  f();
              //...
          }
          function&lt;void()&gt; f;
  };
  
  int main(){
      A a;
      a.f = [] () { cout &lt;&lt; "hello\n"; };
      a.doit();
  }
  </code></pre>
  
  <p>Is there a way to test wheter <code>f</code> was called in function <code>doit()</code>?</p>