title: Overloading on std::function<...>
body: <p>Given the following code :-</p>
  
  <pre><code>#include &lt;algorithm&gt;
  #include &lt;iostream&gt;
  #include &lt;functional&gt;
  #include &lt;string&gt;
  
  void func(std::function&lt;void(void)&gt; param)
  {
      param();
  }
  
  void func(std::function&lt;void(int)&gt; param)
  {
      param(5);
  }
  
  int main(int argc, char* argv[])
  {
      func([] () { std::cout &lt;&lt; "void(void)" &lt;&lt; std::endl; });
      func([] (int i) { std::cout &lt;&lt; "void(int): " &lt;&lt; i &lt;&lt; std::endl; });
  
      std::string line;
      std::getline(std::cin, line);
      return 0;
  }
  </code></pre>
  
  <p>Compile error from VS2010 :-</p>
  
  <pre><code>CppTest.cpp(18): error C2668: 'func' : ambiguous call to overloaded function
  1&gt;          CppTest.cpp(11): could be 'void func(std::tr1::function&lt;_Fty&gt;)'
  1&gt;          with
  1&gt;          [
  1&gt;              _Fty=void (int)
  1&gt;          ]
  1&gt;          CppTest.cpp(6): or       'void func(std::tr1::function&lt;_Fty&gt;)'
  1&gt;          with
  1&gt;          [
  1&gt;              _Fty=void (void)
  1&gt;          ]
  1&gt;          while trying to match the argument list '(`anonymous-namespace'::&lt;lambda0&gt;)'
  1&gt;CppTest.cpp(19): error C2668: 'func' : ambiguous call to overloaded function
  1&gt;          CppTest.cpp(11): could be 'void func(std::tr1::function&lt;_Fty&gt;)'
  1&gt;          with
  1&gt;          [
  1&gt;              _Fty=void (int)
  1&gt;          ]
  1&gt;          CppTest.cpp(6): or       'void func(std::tr1::function&lt;_Fty&gt;)'
  1&gt;          with
  1&gt;          [
  1&gt;              _Fty=void (void)
  1&gt;          ]
  1&gt;          while trying to match the argument list '(`anonymous-namespace'::&lt;lambda1&gt;)'
  </code></pre>
  
  <p>Compile error from g++-4.5</p>
  
  <pre><code>program2.cpp: In function ‘int main(int, char**)’:
  program2.cpp:18:68: error: call of overloaded ‘func(main(int, char**)::&lt;lambda()&gt;)’ is ambiguous
  program2.cpp:6:10: note: candidates are: void func(std::function&lt;void()&gt;)
  program2.cpp:11:10: note:                 void func(std::function&lt;void(int)&gt;)
  program2.cpp:19:79: error: call of overloaded ‘func(main(int, char**)::&lt;lambda(int)&gt;)’ is ambiguous
  program2.cpp:6:10: note: candidates are: void func(std::function&lt;void()&gt;)
  program2.cpp:11:10: note:                 void func(std::function&lt;void(int)&gt;)
  </code></pre>
  
  <p>So it seems the compiler can't figure out that a lambda [] () -> void can only be assigned to a std::function&lt;void(void)&gt;, and a lambda [] (int) -> void can only be assigned to a std::function&lt;void(int)&gt;. Is this supposed to happen or just a deficiency in the compilers?</p>