home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / std / cplus / 1589 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.2 KB  |  67 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!gumby!wupost!cs.uiuc.edu!sparc0b!pjl
  3. From: pjl@cs.uiuc.edu (Paul Lucas)
  4. Subject: Re: Recursive templates
  5. Message-ID: <BxvtxB.CqA@cs.uiuc.edu>
  6. Sender: news@cs.uiuc.edu
  7. Organization: University of Illinois at Urbana-Champaign
  8. References: <Bxu3J4.F93@news.cso.uiuc.edu> <5225@holden.lulea.trab.se>
  9. Date: Tue, 17 Nov 1992 22:46:23 GMT
  10. Lines: 55
  11.  
  12. In <5225@holden.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:
  13.  
  14. >pl2440@meibm31.cen.uiuc.edu (Paul Jay Lucas) writes:
  15. >: In <1992Nov16.220526.21566@borland.com> pete@borland.com (Pete Becker) writes:
  16. >: 
  17. >: >In article <83733@ut-emx.uucp> jamshid@emx.cc.utexas.edu (Jamshid Afshar) writes:
  18. >: >>Has ANSI decided anything about the expansion of a recursive template
  19. >: >>definition?
  20. >: 
  21. >: >    template <unsigned n> class Factorial
  22. >: >    {
  23. >: >    public:
  24. >: >        unsigned eval() { return n*Factorial<n-1>.eval(); }
  25. >: >    };
  26. >: 
  27. >: >    class Factorial<0>
  28. >: >    {
  29. >: >    public:
  30. >: >        unsigned eval() { return 1; }
  31. >: >    };
  32. >: 
  33. >: >    #include <iostream.h>
  34. >: 
  35. >: >    int main()
  36. >: >    {
  37. >: >    Factorial<6> f6;
  38. >: >    cout << f6.eval() << endl;
  39. >: >    return 0;
  40. >: >    }
  41. >: 
  42. >: *****>    Has anyone got a *real* justification for this?  This is a very
  43. >:     obfuscated way of writing factorial.
  44.  
  45. >You should be able to base binary trees on unary trees (which are degenerate
  46. >trees more commonly known as linked lists), trinary trees could be
  47. >based on binary trees, and n-ary trees could be based on (n-1)-ary trees.
  48.  
  49. *****>    I'm not convinced.  List, or unary trees as you call them, serve
  50.     different purposes than do binary trees.  A List class would
  51.     have "list-type" operations on it; a BinaryTree class could have
  52.     LeftChild() and RightChild() functions and wouldn't have
  53.     list-type operations.
  54.     
  55.     Anyway, a Tree<class T,int noOfChildren> class can be
  56.     implemented nicely without recursive templates; I don't see that
  57.     the recursive definition buys you anything.
  58.  
  59. >N-dimension matrixes should be possible to base on N-1-dimension matrixes,
  60. >with 1-dimensional matrixes (arrays) as the recursion-stopper.
  61.  
  62. *****>    What's a 5x3 matrix based on?  4x2, 3x1, 2x(oops!).
  63. -- 
  64.     - Paul J. Lucas                University of Illinois    
  65.       AT&T Bell Laboratories        at Urbana-Champaign
  66.       Naperville, IL            pjl@cs.uiuc.edu
  67.