title: Instantiate member function templates for multiple types
body: <p>I have a several classes with templated member functions and a predefined list of types they will be used with (<a href="https://wandbox.org/permlink/Un6fdSHWpA2Q9ttX" rel="nofollow noreferrer">Wandbox link</a>:</p>
  
  <pre><code>// main.cpp:
  #include "class.h"
  
  int main(int argc, char** argv) {
      A a;
      a.foo(5);
      a.foo(5.);
      B b;
      //b.bar(1,2,3,4); b.bar(1,2,3.,4);
      return 0;
  }
  
  // class.h
  #pragma once
  
  struct A {
      template&lt;typename T&gt; void foo(T x);
  };
  struct B {
      template&lt;typename T&gt; void bar(int p1, int p2, T x, int p3);
  };
  
  
  // class.cpp
  #include &lt;iostream&gt;
  #include "class.h"
  
  template&lt;typename T&gt; void A::foo(T x) {
      std::cout &lt;&lt; x &lt;&lt; std::endl;
  }
  
  // explicit, but very verbose
  // template void A::foo(int);
  // ...
  
  template&lt;typename T&gt; void ignore(T fn) {/* Use fn? */}
  
  template&lt;class Class&gt;
  void instantiate(Class) {
      // List all types the function should be instantiated for here
      ignore(&Class::template foo&lt;int&gt;);
      ignore(&Class::template foo&lt;double&gt;);
  }
  
  // works, instantiates A::foo&lt;int&gt; and A::foo&lt;double&gt;
  template void instantiate(A);
  // How to pass B::foo and additional parameters?
  // template void instantiate(B);
  
  </code></pre>
  
  <p>Typing out every combination of member function and type to be instantiated with works, but it has several drawbacks:</p>
  
  <ul>
  <li>it's tedious</li>
  <li>the whole function signature with every parameter has to typed out, and</li>
  <li>function signature changes have to be made in several places</li>
  <li>adding a single type to the list has to be made for every member function</li>
  </ul>
  
  <p>My workaround as above works on most older compilers I've tested (C++03 compatibility would be a huge plus), but I'm not sure if a smart compiler would be allowed to remove the unused parameter and the function instantiations.</p>
  
  <p>For regular functions, there are <a href="https://stackoverflow.com/a/4697356/73299">workarounds</a>, but as far as I understood, they don't work for member functions.</p>
  
  <p>How can I change my <code>instantiate</code> function to also accept a member function and additional parameters?</p>