This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: explicit specialization in non-namespace scope
- To: egcs at cygnus dot com
- Subject: Re: explicit specialization in non-namespace scope
- From: Nathan Myers <ncm at cygnus dot com>
- Date: Tue, 22 Sep 1998 13:30:49 -0700
- Newsgroups: cygnus.egcs
- Organization: http://www.cantrip.org/
- References: <Pine.GSO.3.96.980921144445.7109I-100000.cygnus.egcs@lystra.lysator.liu.se>, <org1dk8m82.fsf.cygnus.egcs@araguaia.dcc.unicamp.br>
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