title: Why can't I pass a lambda to this function which takes a std::function?
body: <p>The following program is illegal, and I would like to understand why:</p>
  
  <pre><code>#include &lt;functional&gt;
  #include &lt;iostream&gt;
  
  template&lt;typename Result, typename Arg&gt;
  void deduce(std::function&lt;Result(Arg)&gt; f)
  {
    std::cout &lt;&lt; "Result: " &lt;&lt; typeid(Result).name() &lt;&lt; std::endl;
    std::cout &lt;&lt; "Arg: " &lt;&lt; typeid(Arg).name() &lt;&lt; std::endl;
  }
  
  
  int main()
  {
    auto f = [](int x)
    {
      return x + 1;
    };
  
    deduce(f);
  
    return 0;
  }
  </code></pre>
  
  <p><code>clang</code>'s output:</p>
  
  <pre class="lang-none prettyprint-override"><code>$ clang -std=c++11 test.cpp 
  test.cpp:48:3: error: no matching function for call to 'deduce'
    deduce(f);
    ^~~~~~
  test.cpp:26:6: note: candidate template ignored: could not match 'function&lt;type-parameter-0-1 (type-parameter-0-0)&gt;' against '&lt;lambda at test.cpp:34:13&gt;'
  void deduce(std::function&lt;T2(T1)&gt; f)
       ^
  1 error generated.
  </code></pre>
  
  <p>It seems like I ought to be able to convert my lambda to the <code>std::function</code> received by <code>deduce</code>. Why is it not possible for the compiler to apply an appropriate conversion in this case?</p>