Article View: comp.std.c++
Article #3911Re: Syntax for template instantiation and specialization
From: David Vandevoorde
Date: Wed, 03 Apr 1996 17:23
Date: Wed, 03 Apr 1996 17:23
61 lines
2630 bytes
2630 bytes
>>>>> "MH" == Marian Hellema <marian@atcmp.nl> writes:
MH> What is the correct syntax for template instantiation and
MH> specialization?
MH> From my copy of the DWP April 95 I gather:
This has changed somewhat since then...
MH> template<class T>
MH> T max(T a, T b) { return a>b?a:b; }
MH> template int max<int>(int, int); //instantiation
MH> /* OR: */
MH> template int max<>(int, int); //instantiation
(or you can leave out the `<>', I think).
MH> const char* max<const char*>max(const char* a, const char* b)
MH> { /* specialization */ }
Should now be:
template<> // <- note this!
char const*
max<char const*>(char const*, char const*) // ...
MH> const char* max<>(const char* a, const char* b)
MH> { /* specialization */ }
Same thing...
template<> // <- note this!
char const*
max(char const*, char const*) // ...
should be OK. I believe `max<>' would be fine too.
(I'm deducing this from _examples_ in a not-yet-WP rework of the
templates-chapter; I could very well be very wrong).
[...]
MH> 2. Is the following still legal:
MH> int max(int, int); //instantiation??
It is still legal and I believe this is what would be called a
``guiding function declaration''. Without the guiding declaration
max('a', 100);
would not find a match (because conversions are not considered when
matching template arguments); _with_ the guiding declaration, the
regular overloading rules (possibly involving implicit conversions)
apply.
Daveed
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<xsok9zx1f0b.fsf@avs.cs.rpi.edu>Path:
arc1-ca.pugleaf.net!fido.asd.sgi.com!austernReferences:
<4jr0ur$bdh@wn1.sci.kun.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern From: vandevod@cs.rpi.edu (David Vandevoorde) Newsgroups: comp.std.c++ Subject: Re: Syntax for template instantiation and specialization Date: 03 Apr 1996 09:23:04 PST Organization: RPI Computer Science Approved: austern@isolde.mti.sgi.com Message-ID: <xsok9zx1f0b.fsf@avs.cs.rpi.edu> References: <4jr0ur$bdh@wn1.sci.kun.nl> NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: 03 Apr 1996 10:52:36 -0500 In-Reply-To: Marian Hellema's message of 02 Apr 96 13:34:59 GMT X-Newsreader: Gnus v5.1 X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMWKz+Uy4NqrwXLNJAQGWdAH+K5LOm3kMswWOxfv9ok5wudyw+7m53Adb 6neHlqQ+RwthR6O5q/QR28KOfLhY87g7Ze+/3sCekM0lkPSN589OkQ== =DZZW Originator: austern@isolde.mti.sgi.com