explicit specialization in non-namespace scope
Nathan Myers
ncm@cygnus.com
Tue Sep 22 19:41:00 GMT 1998
Alexandre Oliva wrote:
>
> Nathan Myers <ncm@cygnus.com> writes:
> > ... 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; }
>
> Unfortunately, this won't work if A is a template class, because,
> AFAIK, in order to specialize A<...>::factorial<I>, A<...> must be
> fully specialized.
This can be got around by defining a helper function template specialized
to call a nontemplate member. The extra declarations are unpleasant
but need not be exposed to users.
Nathan Myers
ncm@cantrip.org
More information about the Gcc
mailing list