explicit specialization in non-namespace scope
Nathan Myers
ncm@cygnus.com
Mon Sep 21 19:37:00 GMT 1998
Oskar Enoksson wrote:
>
> >>>>> "Nathan" == Nathan Myers <ncm@nospam.cantrip.org> writes:
>
> >> I believe this is incorrect. I find no such restriction.
> >> In addition, in 14.7.3 - Explicit specialization
> >> [temp.expl.spec] we have:
>
> >> -17- A member or a member template may be nested within
> >> many enclosing class templates. If the declaration of an
> >> explicit specialization for such a member appears in
> >> namespace scope, the member declaration shall be preceded
> >> by a template<> for each enclosing class template that is
> >> explicitly specialized.
> >>
> >> It would not be necessary to say "if" above if that were
> >> the only place it could appear.
> >
> >Since I implemented this, I'd better defend myself. :-)
> >
> > [temp.expl.spec]
> >
> > 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. */
>
> Thanks for all answers!
It's still not clear that the above text applies to the case mentioned.
"In the namespace of which the enclosing class is a member" is satisified
both outside and inside the class. When it means to say "not in a class
or in a block", it says "at namespace scope" or sometimes "in namespace
scope"; these are changed from "at global scope" which is what it said
before we had namespaces. "In the namespace of" does not imply "only
at namespace scope".
> I can also report that Digital cxx rejects explicit member template
> specializations.
Digital is a poor choice of compilers to check conformance.
> To bad, it was very useful ...
Anyhow, all is not lost. You can specialize this member anyway,
even in egcs with bug added, just not as cleanly as you wanted:
struct A {
template <int I> inline int factorial();
};
template <> inline int A::f<0>() { return 1; }
template <int I> inline void A::f<I>() { return f<I-1>() * I; }
Nathan Myers
ncm@cantrip.org
More information about the Gcc
mailing list