title: Explicit instantiation of member function template of class template
body: <p>Supposing I have  a class template in my header file with a member function template.</p>
  
  <pre><code>//file.hxx
  template&lt;class T&gt;
  struct A {
      T val;
      template&lt;class U&gt; foo(U a);
  };
  </code></pre>
  
  <p>and I have in a .cpp the implementation of foo:</p>
  
  <pre><code>//file.cpp
  #include "file.hxx"
  #include &lt;typeinfo&gt;
  template&lt;class T&gt; template&lt;class U&gt;
  A&lt;T&gt;::foo&lt;U&gt;(U a){
      std::cout &lt;&lt; "Type T: " &lt;&lt; typeid(val).name() &lt;&lt; std::endl;
      std::cout &lt;&lt; "Type U: " &lt;&lt; typeid(a).name() &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>If I want to explicitly instantiate my class and member function in the .cpp file for, say, int and float, I need something like:</p>
  
  <pre><code>template struct A&lt;int&gt;;
  template struct A&lt;float&gt;;
  template A&lt;int&gt;::foo&lt;int&gt;(int);
  template A&lt;int&gt;::foo&lt;float&gt;(float);
  template A&lt;float&gt;::foo&lt;int&gt;(int);
  template A&lt;float&gt;::foo&lt;float&gt;(float);
  </code></pre>
  
  <p>which becomes a little verbose if I start having a lot of types of T and U. Is there any faster way to do this and still having the explicit instantiation of the templates in the cpp file? I was imagining something like</p>
  
  <pre><code>template&lt;class T&gt;
  template A&lt;T&gt;::foo&lt;int&gt;(int);
  template&lt;class T&gt;
  template A&lt;T&gt;::foo&lt;float&gt;(float);
  template struct A&lt;int&gt;;
  template struct A&lt;float&gt;;
  </code></pre>
  
  <p>but it doesn't work.</p>