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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!spool.mu.edu!darwin.sura.net!uvaarpa!cv3.cv.nrao.edu!cv3!dschieb
  3. From: dschieb@muse.cv.nrao.edu (Darrell Schiebel)
  4. Subject: template disappointments ... (suggestions?)
  5. Message-ID: <DSCHIEB.92Dec29133556@muse.cv.nrao.edu>
  6. Sender: news@nrao.edu
  7. Organization: National Radio Astronomy Observatory
  8. Distribution: comp
  9. Date: Tue, 29 Dec 1992 18:35:56 GMT
  10. Lines: 53
  11.  
  12.  
  13. I am fairly disappointed with the template implementation in Sun's SC2.0.1
  14. (and cfront 3.0 (I suppose)). So far two things are particularly annoying:
  15.  
  16.     (1) The inability to derive templated classes from a non-templated 
  17.         base class of the same name:
  18.         class typeinfo {};
  19.         template<class t> class typeinfo : public typeinfo {};
  20.  
  21.     (2) but worse than this minor item, it seems as though it is 
  22.         impossible to compose templates from templates:
  23.         template<class t> class vector {};
  24.         template<class t> class list {};
  25.  
  26.         list<vector<int>> list_vec_int;
  27.  
  28.         certainly various kludges will work some of the time:
  29.  
  30.         typedef vector<int> fred;
  31.         list<fred> list_vec_int;
  32.  
  33.         it is certainly unfortunate that one must enumerate each
  34.         of the templated expansions via typedefs in order to be able
  35.         to use them in other templates. In addition this is not always
  36.         possible:
  37.  
  38.         class typeinfo {};
  39.         template<class t> class typeinfo_ : public typeinfo {};
  40.         template<class t> class vector {};
  41.  
  42.         template<class t>  const typeinfo *typeid(vector<t> *) {
  43.           static typeinfo_<vector<t>> *storedId = 0;
  44.                            ^^^^^^^^^
  45.         one gets a error like:
  46.         "test3.C", line 110: error:  type expected for name
  47.  
  48.         Try our little trick from before:
  49.  
  50.         template<class t>  const typeinfo *typeid(vector<t> *) {
  51.           typedef vector<t> fred;
  52.           static typeinfo_<fred> *storedId = 0;
  53.  
  54.         And one gets:
  55.         "test3.C", line 102: sorry, not implemented: local typedef fred within template function
  56.  
  57. I was afraid that the implementors would end up making template second class.
  58. I think I was better off with TI's cpp. Does anyone have any suggestions?
  59. I haven't finished reading all of the documentation so I could have missed
  60. something. Thanks for any suggestions.
  61.  
  62.  
  63.                             Darrell Schiebel
  64.                             (dschieb@nrao.edu)
  65.