title: Pass lambda as template function parameter
body: <p>Why doesn't the following code compile (in C++11 mode)?</p>
  
  <pre><code>#include &lt;vector&gt;
  
  template&lt;typename From, typename To&gt;
  void qux(const std::vector&lt;From&gt;&amp;, To (&amp;)(const From&amp;)) { }
  
  struct T { };
  
  void foo(const std::vector&lt;T&gt;&amp; ts) {
      qux(ts, [](const T&amp;) { return 42; });
  }
  </code></pre>
  
  <p>The error message is:</p>
  
  <pre><code>prog.cc:9:5: error: no matching function for call to 'qux'
      qux(ts, [](const T&amp;) { return 42; });
      ^~~
  prog.cc:4:6: note: candidate template ignored: could not match 'To (const From &amp;)' against '(lambda at prog.cc:9:13)'
  void qux(const std::vector&lt;From&gt;&amp;, To (&amp;)(const From&amp;)) { }
       ^
  </code></pre>
  
  <p>But it doesn't explain why it couldn't match the parameter.</p>
  
  <p>If I make <code>qux</code> a non-template function, replacing <code>From</code> with <code>T</code> and <code>To</code> with <code>int</code>, it compiles.</p>