home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- 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
- From: pl2440@meibm31.cen.uiuc.edu (Paul Jay Lucas)
- Subject: Re: Recursive templates
- References: <83733@ut-emx.uucp> <1992Nov16.220526.21566@borland.com>
- Message-ID: <Bxu3J4.F93@news.cso.uiuc.edu>
- Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
- Organization: University of Illinois at Urbana
- Date: Tue, 17 Nov 1992 00:18:39 GMT
- Lines: 33
-
- In <1992Nov16.220526.21566@borland.com> pete@borland.com (Pete Becker) writes:
-
- >In article <83733@ut-emx.uucp> jamshid@emx.cc.utexas.edu (Jamshid Afshar) writes:
- >>Has ANSI decided anything about the expansion of a recursive template
- >>definition?
-
- > template <unsigned n> class Factorial
- > {
- > public:
- > unsigned eval() { return n*Factorial<n-1>.eval(); }
- > };
-
- > class Factorial<0>
- > {
- > public:
- > unsigned eval() { return 1; }
- > };
-
- > #include <iostream.h>
-
- > int main()
- > {
- > Factorial<6> f6;
- > cout << f6.eval() << endl;
- > return 0;
- > }
-
- *****> Has anyone got a *real* justification for this? This is a very
- obfuscated way of writing factorial.
- --
- - Paul J. Lucas University of Illinois
- AT&T Bell Laboratories at Urbana-Champaign
- Naperville, IL pjl@cs.uiuc.edu
-