🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1103

Re: Recursive templates

#1103
From: Johan Bengtsson
Date: Tue, 17 Nov 1992 16:28
44 lines
2041 bytes
pl2440@meibm31.cen.uiuc.edu (Paul Jay Lucas) writes:
: 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.

You should be able to base binary trees on unary trees (which are degenerate
trees more commonly known as linked lists), trinary trees could be
based on binary trees, and n-ary trees could be based on (n-1)-ary trees.

N-dimension matrixes should be possible to base on N-1-dimension matrixes,
with 1-dimensional matrixes (arrays) as the recursion-stopper.

The details are left as an exercise for the reader (:-).
-- 
--------------------------------------------------------------------------
| Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden  |
| Johan.Bengtsson@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490  |
--------------------------------------------------------------------------
Technical Details
Message-ID: <5225@holden.lulea.trab.se>
Path: arc1-ca.pugleaf.net!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
References: <Bxu3J4.F93@news.cso.uiuc.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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
From: jbn@lulea.trab.se (Johan Bengtsson)
Newsgroups: comp.std.c++
Subject: Re: Recursive templates
Message-ID: <5225@holden.lulea.trab.se>
Date: 17 Nov 92 16:28:21 GMT
References: <Bxu3J4.F93@news.cso.uiuc.edu>
Organization: Telia Research AB, Aurorum 6, 951 75 Lulea, Sweden
Lines: 44
X-Newsreader: Tin 1.1 PL4