This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: static template specialization
- From: Martin Sebor <sebor at roguewave dot com>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 19 Nov 2001 10:46:10 -0700
- Subject: Re: static template specialization
- Organization: Rogue Wave Software, Inc.
- References: <3BF8C677.6BF8C9E7@mindmaker.hu>
- Reply-to: gcc-bugs at gcc dot gnu dot org
[Get raw message]
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