title: Template Conundrum
body: <p>I have encountered a C++ template conundrum. I've tried to trim it down to the bare minimum, and now I'm not even sure if what I'm trying to do is possible. Take a look at the following code (in some .h file).</p>
  
  <pre><code>template&lt;typename T&gt;
  class A
  {
  public:
      template&lt;typename S&gt;
      void f(S x);
  };
  
  class B1 { };
  
  template&lt;typename S&gt;
  class B2 { };
  
  //This one works:
  template&lt;&gt;
  template&lt;typename S&gt;
  void A&lt;B1&gt;::f(S x)
  {
  }    
  
  //This one does not work:
  template&lt;&gt;
  template&lt;typename S&gt;
  void A&lt;B2&lt;S&gt;&gt;::f(S x)
  {
  }
  </code></pre>
  
  <p>In my <code>main</code> function I have something like this:</p>
  
  <pre><code>//This one works:
  A&lt;B1&gt; first;
  first.f&lt;int&gt;(5);
  
  //This one does not work:
  A&lt;B2&lt;int&gt;&gt; second;
  second.f&lt;int&gt;(5);
  </code></pre>
  
  <p>The error message I get because of the second part is</p>
  
  <pre><code>error C3860: template argument list following class
               template name must list parameters in the
               order used in template parameter list
  
  error C3855: 'A&lt;T&gt;': template parameter 'T' is
               incompatible with the declaration
  </code></pre>
  
  <p>Any idea what the problem is?</p>
  
  <hr>
  
  <h1>Edit</h1>
  
  <p>To make the problem more concrete, here's my motivation.  I want the function <code>f</code> above to have specializations for <code>T=std::tuple&lt;T1, T2&gt;</code>, <code>T=std::tuple&lt;T1, T2, T3&gt;</code>, and <code>T=std::tuple&lt;T1, T2, T3, T4&gt;</code>, where the types in the <code>tuple</code> are still unbound.</p>