Article View: comp.std.c++
Article #1098Re: Recursive templates
From: Pete Becker
Date: Mon, 16 Nov 1992 22:05
Date: Mon, 16 Nov 1992 22:05
29 lines
1044 bytes
1044 bytes
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;
}
That's from memory, so I may have some of the details wrong, but it
worked in BC 3.0, and from discussions I've had the same sort of thing works
with cfront.
-- Pete
Technical Details
Message-ID:
<1992Nov16.220526.21566@borland.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!ukma!netsys!decwrl!borland.com!peteReferences:
<83733@ut-emx.uucp>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!ukma!netsys!decwrl!borland.com!pete From: pete@borland.com (Pete Becker) Subject: Re: Recursive templates Message-ID: <1992Nov16.220526.21566@borland.com> Originator: pete@genghis.borland.com Sender: news@borland.com (News Admin) Organization: Borland International References: <83733@ut-emx.uucp> Date: Mon, 16 Nov 1992 22:05:26 GMT Lines: 32