This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: explicit specialization in non-namespace scope


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]