Why is partial specialziation of a nested class template allowed, while complete isn't?

Posted by drhirsch on Stack Overflow See other posts from Stack Overflow or by drhirsch
Published on 2010-03-29T12:15:58Z Indexed on 2010/03/29 12:23 UTC
Read the original article Hit count: 287

Filed under:
|
|
    template<int x> struct A {                                                                                                    
        template<int y> struct B {};.                                                                                             
        template<int y, int unused> struct C {};                                                                                  
    };                                                                                                                            

    template<int x> template<> 
    struct A<x>::B<x> {}; // error: enclosing class templates are not explicitly specialized

    template<int x> template<int unused> 
    struct A<x>::C<x, unused> {}; // ok

So why is the explicit specialization of a inner, nested class (or function) not allowed, if the outer class isn't specialiced too? Strange enough, I can work around this behaviour if I only partially specialize the inner class with simply adding a dummy template parameter. Makes things uglier and more complex, but it works.

Note: I need this feature for recursive templates of the inner class for a set of the outer class.

To make things even more complicate, in reality I only need a template function instead of the inner class. But partial specialization of functions is generally disallowed somewhere else in the standard ^^

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates