title: How to get correct resolution of variadic template function without being too verbose
body: <p>My question is about a compilation error I was getting when defining and using a variadic function. I will give a minimal example below.</p>
  
  <p>First I defined a function to print an object:
  (all code is <a href="https://ideone.com/SwhUPd" rel="nofollow">here</a>)</p>
  
  <pre><code>template &lt;typename T&gt;
  void print(T t){
      std::cout &lt;&lt; t&lt;&lt;std::endl;
  }
  </code></pre>
  
  <p>Next, I defined a function that will allow you to transform an object and then print it:</p>
  
  <pre><code>template &lt;typename T&gt;
  void print(T t,std::function&lt;void(T&amp; t)&gt; transformer){
      transformer(t);
      std::cout &lt;&lt; t &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Next, I wanted to define a function that will let you call either of the two above functions, but will result in printing a label and the result. I can achieve this with a variadic function template:</p>
  
  <pre><code>template &lt;typename... Params&gt;
  void printLabeled(std::string label,Params... params){
      std::cout &lt;&lt; label &lt;&lt; ": ";
      print(params...);
  }
  </code></pre>
  
  <p>Now I can try to use the code. The main thing I want to do is call <code>printLabeled("answer",1,{[](int&amp; num){num+=1;}});</code>, but this doesn't work. I have to do something more verbose. Is there any way to do the function call without be more verbose than <code>printLabeled("answer",1,{[](int&amp; num){num+=1;}});</code>? Again, you can run the code <a href="https://ideone.com/SwhUPd" rel="nofollow">here</a>. Examples of function calls that work and don't work are below.</p>
  
  <pre><code>int main() {
      //prints the number '1', as expected
      print(1);
  
      //prints the number the label "answer" and then the number one
      printLabeled("answer",1);
  
      //I intended this to increment 1 to 2 and then print 2,
      //but I guess the lambda does not get converted to an std::function,
      //so this doesn't work
      //print(1,[](int&amp; num){num+=1;});
  
      //This does was the above line was intended to do
      print(1,{[](int&amp; num){num+=1;}});
  
      //I intended this to be the labeled version of the above line,
      //but for some reason, this doesn't work anymore
      // printLabeled("answer",1,{[](int&amp; num){num+=1;}});
  
      //This labeled version does work finally,
      //but its pretty verbose
      printLabeled("answer",1,std::function&lt;void(int&amp;)&gt;([](int&amp; num){num+=1;}));
      return 0;
  }
  </code></pre>