home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / std / cplus / 1588 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  1.9 KB

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!sdd.hp.com!wupost!gumby!yale!yale.edu!ira.uka.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sunic!hagbard!loglule!jbn
  2. From: jbn@lulea.trab.se (Johan Bengtsson)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Recursive templates
  5. Message-ID: <5225@holden.lulea.trab.se>
  6. Date: 17 Nov 92 16:28:21 GMT
  7. References: <Bxu3J4.F93@news.cso.uiuc.edu>
  8. Organization: Telia Research AB, Aurorum 6, 951 75 Lulea, Sweden
  9. Lines: 44
  10. X-Newsreader: Tin 1.1 PL4
  11.  
  12. pl2440@meibm31.cen.uiuc.edu (Paul Jay Lucas) writes:
  13. : In <1992Nov16.220526.21566@borland.com> pete@borland.com (Pete Becker) writes:
  14. : >In article <83733@ut-emx.uucp> jamshid@emx.cc.utexas.edu (Jamshid Afshar) writes:
  15. : >>Has ANSI decided anything about the expansion of a recursive template
  16. : >>definition?
  17. : >    template <unsigned n> class Factorial
  18. : >    {
  19. : >    public:
  20. : >        unsigned eval() { return n*Factorial<n-1>.eval(); }
  21. : >    };
  22. : >    class Factorial<0>
  23. : >    {
  24. : >    public:
  25. : >        unsigned eval() { return 1; }
  26. : >    };
  27. : >    #include <iostream.h>
  28. : >    int main()
  29. : >    {
  30. : >    Factorial<6> f6;
  31. : >    cout << f6.eval() << endl;
  32. : >    return 0;
  33. : >    }
  34. : *****>    Has anyone got a *real* justification for this?  This is a very
  35. :     obfuscated way of writing factorial.
  36.  
  37. You should be able to base binary trees on unary trees (which are degenerate
  38. trees more commonly known as linked lists), trinary trees could be
  39. based on binary trees, and n-ary trees could be based on (n-1)-ary trees.
  40.  
  41. N-dimension matrixes should be possible to base on N-1-dimension matrixes,
  42. with 1-dimensional matrixes (arrays) as the recursion-stopper.
  43.  
  44. The details are left as an exercise for the reader (:-).
  45. -- 
  46. --------------------------------------------------------------------------
  47. | Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden  |
  48. | Johan.Bengtsson@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490  |
  49. --------------------------------------------------------------------------
  50.