title: Passing a templated functor as an argument to a templated function in C++
body: <p>I am trying to pass a templated functor into a templated function.
  The code looks something like this:</p>
  <pre class="lang-cpp prettyprint-override"><code>template&lt;typename T&gt;
  T func_1(T &amp;a) {
      return a;
  }
  
  template &lt;typename T&gt;
  T test(T &amp;a, std::function&lt;T(T&amp;)&gt; &amp;func){
      return func(a);
  }
  
  int main(){
      int a = 5;
      std::cout &lt;&lt; test(a, func_1) &lt;&lt; std::endl;
  }
  </code></pre>
  <p>However, I get the following compile error:</p>
  <blockquote>
  <p>invalid initialization of non-const reference of type ‘std::function&lt;int(int&amp;)&gt;&amp;’ from an rvalue of type ‘’</p>
  </blockquote>
  <p>The code works if I remove the template. Can someone help me understand why?</p>