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

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!uwm.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!meibm31.cen.uiuc.edu!pl2440
  3. From: pl2440@meibm31.cen.uiuc.edu (Paul Jay Lucas)
  4. Subject: Re: Recursive templates
  5. References: <83733@ut-emx.uucp> <1992Nov16.220526.21566@borland.com>
  6. Message-ID: <Bxu3J4.F93@news.cso.uiuc.edu>
  7. Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
  8. Organization: University of Illinois at Urbana
  9. Date: Tue, 17 Nov 1992 00:18:39 GMT
  10. Lines: 33
  11.  
  12. In <1992Nov16.220526.21566@borland.com> pete@borland.com (Pete Becker) writes:
  13.  
  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.  
  18. >    template <unsigned n> class Factorial
  19. >    {
  20. >    public:
  21. >        unsigned eval() { return n*Factorial<n-1>.eval(); }
  22. >    };
  23.  
  24. >    class Factorial<0>
  25. >    {
  26. >    public:
  27. >        unsigned eval() { return 1; }
  28. >    };
  29.  
  30. >    #include <iostream.h>
  31.  
  32. >    int main()
  33. >    {
  34. >    Factorial<6> f6;
  35. >    cout << f6.eval() << endl;
  36. >    return 0;
  37. >    }
  38.  
  39. *****>    Has anyone got a *real* justification for this?  This is a very
  40.     obfuscated way of writing factorial.
  41. -- 
  42.     - Paul J. Lucas                University of Illinois    
  43.       AT&T Bell Laboratories        at Urbana-Champaign
  44.       Naperville, IL            pjl@cs.uiuc.edu
  45.