home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13363 < prev    next >
Encoding:
Text File  |  1992-09-08  |  1.3 KB  |  38 lines

  1. Path: sparky!uunet!snorkelwacker.mit.edu!ai-lab!life.ai.mit.edu!tmb
  2. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  3. Newsgroups: comp.lang.c++
  4. Subject: backwards references in templates
  5. Message-ID: <TMB.92Sep7163720@arolla.idiap.ch>
  6. Date: 7 Sep 92 20:37:20 GMT
  7. Sender: news@ai.mit.edu
  8. Reply-To: tmb@idiap.ch
  9. Distribution: comp
  10. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  11.     Perceptive)
  12. Lines: 24
  13.  
  14. The following definition of Foo appears to be illegal (GNU C++ doesn't
  15. accept it, and the ARM doesn't seem to sanction it):
  16.  
  17.     template <class K,K x>
  18.     struct Foo {
  19.         K y;
  20.         Foo() { y = x; }
  21.     };
  22.     
  23. This restriction on the uses of template arguments (as in "Foo") is a
  24. serious problem, since such dependencies occur frequently.
  25.  
  26. First, I'd like to know: are such template constructs indeed
  27. prohibited by the language definition?
  28.  
  29. Second, I'd like to know what alternative paradigms there are.  The
  30. only one that I can think of involves nested template classes
  31. (inconvenient, doesn't work in any existing compiler). In some cases,
  32. non-type template arguments like "x" can also be made (static) data
  33. members, but that implies runtime space/time overhead, and the use of
  34. static members requires a separate source file for initialization.
  35. Are there any more satisfactory solutions?
  36.  
  37.                     Thomas.
  38.