title: Using gmock Matchers to set std::function as method argument inside EXPECT_CALL
body: <p>Trying to unit test private callback method of a class</p>
  
  <pre><code>class MyClass{
  public:
   MyClass(Component&amp; component) : component(component) {};
   void Init();
  private:
   void callback();
   Component component;
  }
  
  void MyClass::callback(const std::string&amp; text)
  {
  ...
  }
  </code></pre>
  
  <p>Callback is registered in public Init method using component member (component.register() method) which I can mock.</p>
  
  <pre><code>void MyClass::Init(){
     auto cb = std::bind(&amp;MyClass::callback, this, std::placeholders::_1);
     connection = component.register(ESomeType::MyType, std::move(cb));
  }
  
  MOCK_METHOD2(register, boost::signals2::connection(ESomeType, std::function&lt;void(const std::string&amp;)&gt;));
  </code></pre>
  
  <p>As suggested here
  <a href="https://stackoverflow.com/questions/37591112/how-to-unit-test-the-stdbind-function-using-gtest">How to unit test the std::bind function using gtest?</a>
  I want to EXPECT_CALL of a component.register() function and store passed std::function&lt;> argument in unit test local variable using SaveArg.
  Then using that variable I should be able to call callback for testing purposes.</p>
  
  <p>As component.register() is overloaded function I need to pass exact argument types to EXPECT_CALL using Matchers to avoid ambiguity. </p>
  
  <p>Unfortunately, having problems with setting Matcher type.</p>
  
  <p>Current test code:</p>
  
  <pre><code>ComponentMock component;
  MyClass testClass(component);
  
  std::function &lt;void(const std::string&amp; text)&gt; componentCallback;
  
  EXPECT_CALL(component, register(Matcher&lt;ESomeType&gt;(ESomeType::MyType),
                            Matcher&lt; void(const std::string&amp; text) &gt;(componentCallback)))
                            .WillOnce(testing::SaveArg&lt;1&gt;(&amp;componentCallback;);
  
  testClass.init();
  
  testClass.componentCallback( ... );
  </code></pre>
  
  <p>Is the approach correct in the first place? If yes, could you help me with following error:</p>
  
  <pre><code>In file included from gmock-generated-function-mockers.h:43:0, gmock.h:61, ComponentMock.hpp:16, Test.cpp:18:
  In member function 'void Test_initialize()':
  Test.cpp: error: no matching function for call to 'testing::Matcher&lt;void(const std::basic_string&lt;char&gt;&amp;)&gt;::Matcher(std::function&lt;void(const std::basic_string&lt;char&gt;&amp;)&gt;&amp;)'
                                    Matcher&lt; void(const std::string&amp; string) &gt;(componentCallback)));
                                                                                          ^
  ...
  gmock-matchers.h:3747:1: note: candidate: testing::Matcher&lt;T&gt;::Matcher(T) [with T = void(const std::basic_string&lt;char&gt;&amp;)]
   Matcher&lt;T&gt;::Matcher(T value) { *this = Eq(value); }
   ^~~~~~~~~~
  gmock-matchers.h:3747:1: note:   no known conversion for argument 1 from 'std::function&lt;void(const std::basic_string&lt;char&gt;&amp;)&gt;' to 'void (*)(const std::basic_string&lt;char&gt;&amp;)'
  ...
  </code></pre>