home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15843 < prev    next >
Encoding:
Text File  |  1992-11-06  |  2.3 KB  |  76 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!concert!sas!mozart.unx.sas.com!sasghm
  3. From: sasghm@theseus.unx.sas.com (Gary Merrill)
  4. Subject: A template or not a template?
  5. Originator: sasghm@theseus.unx.sas.com
  6. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  7. Message-ID: <Bx9DuJ.3pp@unx.sas.com>
  8. Date: Thu, 5 Nov 1992 19:51:55 GMT
  9. Nntp-Posting-Host: theseus.unx.sas.com
  10. Organization: SAS Institute Inc.
  11. Keywords: templates
  12. Lines: 62
  13.  
  14.  
  15. Well, I've unearthed a copy of the second edition of Lippman
  16. and find it to be quite good in general (I'll omit any minor
  17. criticisms I may have at this point).  I've been looking at it
  18. pretty closely (in conjunction with other stuff) and trying to
  19. extract a semantics for templates.  In the process, the following
  20. (admittedly perverse) example occurred to me:
  21.  
  22.     template <class T> class Foo {
  23.         // Doesn't much matter what's here
  24.         T x;
  25.         };
  26.  
  27.     template <class T> class Foo<int> {
  28.         // Likewise
  29.         T *p;
  30.         };
  31.  
  32. Now clearly the first is a template-declaration.  So is the
  33. second!  Note that since 'Foo' is a template-name, then
  34. 'Foo<int>' is a template-class-id (I'm using stardard and ARM
  35. terminology here).  Indeed,
  36.  
  37.     class Foo<int> {
  38.         // Likewise
  39.         T *p;
  40.     };
  41.  
  42. would appear to be a *specialized instance* (Lippman terminology).
  43. Certainly it has to be counted as a *declaration* if
  44.  
  45.  
  46.     class Foo {
  47.         // Doesn't much matter what's here
  48.         T x;
  49.         };
  50.  
  51. is a declaration (which it is).  In short, the second apparent
  52. template-declaration follows the grammar and violates no constraints
  53. I have seen anywhere.
  54.  
  55. But what does it *mean*?  Moreover, what does the use of the new
  56. template-name ('Foo<int>') mean in various contexts?  Consider,
  57.  
  58.     Foo<char> c;  // unproblematic
  59.  
  60.     Foo<int><double> d;  // Likewise unproblematic, I think.
  61.  
  62.     Foo<int> i;    // ?????
  63.  
  64. Apparently I am not alone in my confusion.  The latest version of
  65. g++ accepts both template-declarations.  It handles nicely the
  66. declaration of 'c' above.  On both of the other two declarations
  67. it suicides with an "Internal compiler error".
  68.  
  69. Do we perhaps need to tighten up the syntax of template declarations
  70. a bit?  Any thoughts?
  71.  
  72. -- 
  73. Gary H. Merrill  [Principal Systems Developer, C Compiler Development]
  74. SAS Institute Inc. / SAS Campus Dr. / Cary, NC  27513 / (919) 677-8000
  75. sasghm@theseus.unx.sas.com ... !mcnc!sas!sasghm
  76.