[Q] about template specialization

Nathan Myers ncm@cygnus.com
Mon Apr 27 17:27:00 GMT 1998


Alexandre Oliva wrote:
> 
> Ruslan Shevchenko <Ruslan@Shevchenko.Kiev.UA> writes:
> 
> > template<class K, class E> inline
> > const K& default_key(const E&);
> 
> > template<class T> inline
> > const T& default_key(const T& x)
> 
> >    virtual const K& get_key(const E& x)
> >     { return  default_key<K,E>(x); }
> 
> > I think  that  X<Y,Y>::get_key must call specialization (i. e. second
> > definition)
> 
> There's not such thing as partial specialization of a function
> templates.  You have just overloaded `default_key' with two different
> template functions.  In this case, you will always have to explicitly
> specify template arguments.  Since you specify default_key<K,E>, not
> just default_key<K>, you are selecting the first definition.

When the specialization semantics of function templates are not
what you want, you can use a function object to get a similar
result.  A function template can still be used for the interface.

Nathan Myers
ncm@cantrip.org



More information about the Gcc mailing list