Specialization of template template parameters
<p>This is a sequel question (on a different topic) to an <a href="http://stackoverflow.com/questions/5642819/reverse-traits-lookup">earlier question</a>. The code below incorporates Dehstil's suggestion to use specialization.</p>

<p>How should a function that has template template parameters be specialized?</p>

<p>The code below (in which the two specialization lines do not compile) make the question concrete.</p>

<pre><code>#include &lt;cassert&gt;

template&lt;typename S&gt; struct PA1 {};
template&lt;typename S&gt; struct PA2 {};
template&lt;typename S&gt; struct PB  {};
template&lt;typename S&gt; struct PC  {};

template&lt;typename S&gt; struct A1 { typedef PA1&lt;S&gt; P; };
template&lt;typename S&gt; struct A2 { typedef PA2&lt;S&gt; P; };
template&lt;typename S&gt; struct B  { typedef PB &lt;S&gt; P; };
template&lt;typename S&gt; struct C  { typedef PC &lt;S&gt; P; };

template&lt;typename S, template&lt;typename&gt; class T&gt; char fn(typename T&lt;S&gt;::P);

template&lt;typename S, template&lt;typename&gt; class T&gt; char fn(typename T&lt;S&gt;::P)
{
    return 'a';
}

template&lt;typename S&gt; char fn&lt;B&lt;S&gt; &gt;(B&lt;S&gt;::P) {   return 'b';  }
template&lt;typename S&gt; char fn&lt;C&lt;S&gt; &gt;(C&lt;S&gt;::P) {   return 'c';  }

int main()
{
    PA1&lt;int&gt; pa1;
    PA2&lt;int&gt; pa2;
    PB&lt;int&gt;  pb;
    PC&lt;int&gt;  pc;
    assert( (fn&lt;int, A1&gt;(pa1)) == 'a' );
    assert( (fn&lt;int, A2&gt;(pa2)) == 'a' );

    assert( (fn&lt;int, B&gt;(pb)) == 'b' );
    assert( (fn&lt;int, C&gt;(pc)) == 'c' );
}
</code></pre>

<p>It's important for the four function calls fn&lt;...,...>() to have identical signatures when called since they will themselves reside in a template class that applies to the four classes A1/A2/B/C.</p>
