static template specialization

Martin Sebor sebor@roguewave.com
Wed Nov 7 10:45:00 GMT 2001


Levente Farkas wrote:
> 
> hi,
> Is this code incorrect or it's just a gcc bug?
> ------------
> class A
> {
>   template<typename T>
>     static int get(T) { return 0; }
>   template<>
>     static int get(int) { return 1; }
>   template<>
>     static int get(double) { return 2; }
> };

Unfortunately, this is disallowed in 14.7.3, p2:

    An explicit specialization shall be declared in the namespace
    of which the template is a member, or, for member templates,
    in the namespace of which the enclosing class or enclosing class
    template is a member. An explicit specialization of a member
    function, member class or static data member of a class template
    shall be declared in the namespace of which the class template
    is a member. ...

Apparently, the restriction exists to make the feature easier to
implement, specifically in the case of explicit specialization of
member templates of class templates. It sure would be a nice thing
to have, though. Perhaps as a g++ extension until the restriction
is lifted from the standard?

Regards
Martin



More information about the Gcc-bugs mailing list