title: C++ special instance of template function for some type which is a template class itself
body: <p>I got trouble in creating special instance of member template function of non-template class. I have, for example, class A with template member function F:</p>
  
  <pre><code>class A
     {public:
        template &lt;class T&gt; int F (T arg) const;
        ....
     }
  </code></pre>
  
  <p>and want to have a special instance of this template function F for type B:</p>
  
  <pre><code>class B;
  ...
  template &lt;&gt; void A::F (B arg) const //GOOD!
  </code></pre>
  
  <p>and it works perfectly, until appears that B is a template itself!</p>
  
  <p>This code </p>
  
  <pre><code>template &lt;class T&gt; class B ...
  ...
  template &lt;&gt; void A::F (B&lt;T&gt; arg) const //error, T undeclared
  </code></pre>
  
  <p>as well as</p>
  
  <pre><code>template &lt;class T&gt; class B ...
  ...
  template &lt;class T&gt; template &lt;&gt; void A::F (B&lt;T&gt; arg) const //error, too many templates
  </code></pre>
  
  <p>gives compiling error.</p>
  
  <p>The second trouble is, how to declare this special instance (or template instance at whole) to be friend function of class B? (Is does not work even if B is not a template).</p>
  
  <pre><code>class B
     {friend template &lt;&gt; void A::F (B arg) const // error
       // as well as
      template &lt;&gt; friend void A::F (B arg) const // error
     }
  </code></pre>
  
  <p>Is there a way to write code in a way I'm going to at all or it is not possible?</p>