title: C++ template lambda wrapper
body: <p>Can anyone figure out how to make this compile ?</p>
  <p>I'm trying to wrap a lambda in another function that does something (here printing &quot;you know what&quot;) + calling the lambda.</p>
  <p>Best would be to have automatic template parameters deduction.</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;functional&gt;
  #include &lt;utility&gt;
  
  void youKnowWhat(const std::function&lt;void()&gt;&amp;&amp; fun)
  {
      std::cout &lt;&lt; &quot;You know what ?&quot; &lt;&lt; std::endl;
      fun();
  }
  
  template &lt;typename... Args&gt;
  auto youKnowWhatSomething(const std::function&lt;void(Args...)&gt;&amp;&amp; fun)
  {
      return [fun{std::move(fun)}](Args... args)
          {
              youKnowWhat(std::bind(fun, std::forward&lt;Args&gt;(args)...));
          };
  }
  
  int main()
  {
      const auto imHavingSomething([](const std::string&amp; s){
          std::cout &lt;&lt; &quot;Im having &quot; &lt;&lt; s &lt;&lt; std::endl;
      });
  
      const auto youKnowWhatImHavingSomething(youKnowWhatSomething(std::move(imHavingSomething)));
      youKnowWhatImHavingSomething(&quot;fun with templates&quot;);
      youKnowWhatImHavingSomething(&quot;headaches&quot;);
  }
  </code></pre>