Here is the code :
template
struct A
{
template
struct B;
};
template template <> /
Here's an idea based on Xeo's example: First, let's have our candidate primary template:
template <typename T> struct Foo
{
template <typename U> struct Bar { /* ... */ };
/* ... */
};
Now suppose we want to specialize the inner template, hypothetically:
template <typename T> template <> struct Foo<T>::Bar<bool> { /* ... */ }
// not actual C++!
But now suppose there are specializations of Foo
:
template <> struct Foo<int>
{
template <typename U> struct Bar { /* ... */ };
};
template <> struct Foo<char>
{
template <typename U> U Bar() { }
};
Now what if you want to use Foo<S>::Bar<bool>
? When S = char
, we cannot use the inner specialization, because it makes no sense. But if we disallow the inner specialization for all specializations of the outer template, then Foo<int>::Bar<bool>
isn't specialized, while Foo<float>::Bar<bool>
will be specialized. So our hypothetical inner specialization does not apply to Foo<int>
, even though one might have expected that it should.
This isn't a real technical reason that it can't be done, but just an illustration how it would have very unexpected behaviour. (For instance, imagine the specialization for int
was written later, and existing code depended on the inner specialization.)