public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [Q] about template specialization
@ 1998-04-25 11:59 Ruslan Shevchenko
  1998-04-27  0:33 ` Alexandre Oliva
       [not found] ` <orlnsrvlnc.fsf.cygnus.egcs@garnize.lsd.dcc.unicamp.br>
  0 siblings, 2 replies; 3+ messages in thread
From: Ruslan Shevchenko @ 1998-04-25 11:59 UTC (permalink / raw)
  To: egcs; +Cc: egcs

look at the next code:

template<class K, class E>
inline
const K& default_key(const E&);

template<class T>
inline
const T& default_key(const T& x)
{
  return x;
}

than, in

template<class K, class E>
class X
{

........

   virtual const K& get_key(const E& x)
    { return  default_key<K,E>(x); }

};

than, lets look on class X<Y,Y>

I think  that  X<Y,Y>::get_key must call specialization (i. e. second
definition)
Actually, in egcs it is wrong.

So, what standart behavior ?

Thanks.


--

    @=
     //RSSH                              mailto:Ruslan@Shevchenko.Kiev.UA




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Q] about template specialization
  1998-04-25 11:59 [Q] about template specialization Ruslan Shevchenko
@ 1998-04-27  0:33 ` Alexandre Oliva
       [not found] ` <orlnsrvlnc.fsf.cygnus.egcs@garnize.lsd.dcc.unicamp.br>
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 1998-04-27  0:33 UTC (permalink / raw)
  To: rssh; +Cc: egcs

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.

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Q] about template specialization
       [not found] ` <orlnsrvlnc.fsf.cygnus.egcs@garnize.lsd.dcc.unicamp.br>
@ 1998-04-27 17:27   ` Nathan Myers
  0 siblings, 0 replies; 3+ messages in thread
From: Nathan Myers @ 1998-04-27 17:27 UTC (permalink / raw)
  To: egcs

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-04-27 17:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-25 11:59 [Q] about template specialization Ruslan Shevchenko
1998-04-27  0:33 ` Alexandre Oliva
     [not found] ` <orlnsrvlnc.fsf.cygnus.egcs@garnize.lsd.dcc.unicamp.br>
1998-04-27 17:27   ` Nathan Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).