Article View: comp.std.c++
Article #1824Re: Template instantiation question
From: Steve Clamage
Date: Wed, 23 Aug 1995 15:54
Date: Wed, 23 Aug 1995 15:54
34 lines
2007 bytes
2007 bytes
In article AC60F6E1966821CF0@sleipner.nts.mh.se, lars.farm@nts.mh.se (Lars Farm) writes:
>In article <41b09t$ltj@engnews2.Eng.Sun.COM>, clamage@Eng (Steve Clamage) wrote:
>
>>In the mean time, you could write a specialization of Foo<X>::compare
>>that throws an exception or invokes "assert(0)" to allow your code
>>to compile and link. That is, for example, if you use Foo<complex>,
>>you could provide the specialization
>> int Foo<complex>::compare(const complex&) { assert(0); return 0; }
>>which will prevent the compiler from generating a version from the template,
>>and will thus allow your program to compile and link.
>
>Can you specialize just that one function for complex
Yes.
>or do you have to
>specialize the whole class Foo<complex> with all its members to change the
>implementation of Foo<complex>::compare?
No. You can provide individual specializations for selected member
functions of a class if you wish. Often the template version of some
functions is acceptable, but others need a different implementation
than the version supplied by the template. This is an extreme example
where you cannot implement 'compare' at all: mathematical complex
numbers are not well-ordered.
---
Steve Clamage, stephen.clamage@eng.sun.com
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<41fiv1$kqc@engnews2.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: clamage@Eng.Sun.Com (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: Template instantiation question Date: 23 Aug 1995 15:54:09 GMT Organization: Sun Microsystems Inc., Mountain View, CA Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <41fiv1$kqc@engnews2.Eng.Sun.COM> NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: taumet.eng.sun.com Content-Length: 1251 X-Lines: 30 Originator: clamage@taumet