home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18527 < prev    next >
Encoding:
Text File  |  1992-12-29  |  2.5 KB  |  72 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!stanford.edu!EE.Stanford.EDU!sierra!mcgrant
  3. From: mcgrant@gomez.stanford.edu (Michael C. Grant)
  4. Subject: Re: template disappointments ... (suggestions?
  5. In-Reply-To: cflatter@nrao.edu's message of Tue, 29 Dec 1992 20:44:31 GMT
  6. Message-ID: <MCGRANT.92Dec29191250@gomez.stanford.edu>
  7. Sender: usenet@EE.Stanford.EDU (Usenet)
  8. Organization: Information Systems Laboratory, Stanford University
  9. References: <DSCHIEB.92Dec29133556@muse.cv.nrao.edu> <1992Dec29.204431.13413@nrao.edu>
  10. Date: 29 Dec 92 19:12:50
  11. Lines: 59
  12.  
  13.  
  14. In article <1992Dec29.204431.13413@nrao.edu>
  15. cflatter@nrao.edu (Chris Flatters) writes:
  16.    In article 92Dec29133556@muse.cv.nrao.edu,
  17.    dschieb@muse.cv.nrao.edu (Darrell Schiebel) writes:
  18.    >    (1) The inability to derive templated classes from a non-templated 
  19.    >        base class of the same name:
  20.    >        class typeinfo {};
  21.    >        template<class t> class typeinfo : public typeinfo {};
  22. Yeah, that's a bummer. I see no reason why typeinfo and typeinfo<T>
  23. can't be distinguished by any reasonable compiler.
  24.  
  25.    This is according to the ARM:
  26.  
  27.            A class template name must be unique in the program and may not
  28.            be declared to refer to any other template, class, function,
  29.            object, value, or type in the same scope.
  30.                                                            [p343]
  31. What's yer point? That's why this is called 'template disappointments.'
  32.  
  33. Here are mine, both of which I've mentioned before, but nobody has managed
  34. to convince me it can be simulated in the current language.
  35.  
  36. (1) Templated member functions. Someone gave me some lame argument that
  37.     since you can specialize any templated function you can break into
  38.     the private structure of a class, but since there are so many easy
  39.     ways to do that already I don't accept that argument.
  40. (2) A compile-type typeof() operator like GNU's that can be used in
  41.     templates.
  42.  
  43.     For example:
  44.  
  45.     double abs(double);
  46.     double abs(const complex&);
  47.  
  48.     template <class T> foo {
  49.        T data;
  50.        typeof(abs(T)) norm;
  51.        ...
  52.     }
  53.  
  54.     I suppose I wouldn't mind faking it like this if necessary
  55.     (and, of course, if it's possible).
  56.  
  57.     template <class T> typedef T normType<T>;
  58.     typedef double normType<complex>;
  59.  
  60.     template <class T> foo {
  61.         T data;
  62.         normType<T> norm;
  63.        ...
  64.     }
  65.  
  66.     But this is hardly elegant! The typeof() operator would be nicer.
  67.  
  68. Michael C. Grant
  69.  
  70. --
  71. "Long hair, short hair--what's the difference once the head's blowed off?" (?)
  72.