title: Template function as a template argument
body: <p>I've just got confused how to implement something in a generic way in C++. It's a bit convoluted, so let me explain step by step.</p>
  
  <hr>
  
  <p>Consider such code:</p>
  
  <pre><code>void a(int) {
      // do something
  }
  void b(int) {
      // something else
  }
  
  
  void function1() {
      a(123);
      a(456);
  }
  void function2() {
      b(123);
      b(456);
  }
  
  void test() {
      function1();
      function2();
  }
  </code></pre>
  
  <p>It's easily noticable that <code>function1</code> and <code>function2</code> do the same, with the only different part being the internal function.</p>
  
  <p>Therefore, I want to make <code>function</code> generic to avoid code redundancy. I can do it using function pointers or templates. Let me choose the latter for now. <strong>My thinking is that it's better since the compiler will surely be able to inline the functions - am I correct? Can compilers still inline the calls if they are made via function pointers?</strong> This is a side-question.</p>
  
  <p>OK, back to the original point... A solution with templates:</p>
  
  <pre><code>void a(int) {
      // do something
  }
  void b(int) {
      // something else
  }
  
  template&lt;void (*param)(int) &gt;
  void function() {
      param(123);
      param(456);
  }
  
  void test() {
      function&lt;a&gt;();
      function&lt;b&gt;();
  }
  </code></pre>
  
  <p>All OK. But I'm running into a problem: Can I still do that if <code>a</code> and <code>b</code> are generics themselves?</p>
  
  <pre><code>template&lt;typename T&gt;
  void a(T t) {
     // do something
  }
  
  template&lt;typename T&gt;
  void b(T t) {
     // something else
  }
  
  template&lt; ...param... &gt; // ???
  void function() {
      param&lt;SomeType&gt;(someobj);
      param&lt;AnotherType&gt;(someotherobj);
  }
  
  void test() {
      function&lt;a&gt;();
      function&lt;b&gt;();
  }
  </code></pre>
  
  <p>I know that a template parameter can be one of:</p>
  
  <ul>
  <li>a type, </li>
  <li>a template type,</li>
  <li>a value of a type.</li>
  </ul>
  
  <p>None of those seems to cover my situation. My main question is hence: <strong>How do I solve that, i.e. define  <code>function()</code> in the last example?</strong> </p>
  
  <p><em>(Yes, function pointers seem to be a workaround in this exact case - provided they can also be inlined - but I'm looking for a general solution for this class of problems).</em></p>