🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Recursive templates

#1104
From: Paul Lucas
Date: Tue, 17 Nov 1992 22:46
55 lines
2328 bytes
In <5225@holden.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:

>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.

*****>	I'm not convinced.  List, or unary trees as you call them, serve
	different purposes than do binary trees.  A List class would
	have "list-type" operations on it; a BinaryTree class could have
	LeftChild() and RightChild() functions and wouldn't have
	list-type operations.
	
	Anyway, a Tree<class T,int noOfChildren> class can be
	implemented nicely without recursive templates; I don't see that
	the recursive definition buys you anything.

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

*****>	What's a 5x3 matrix based on?  4x2, 3x1, 2x(oops!).
-- 
	- Paul J. Lucas				University of Illinois	
	  AT&T Bell Laboratories		at Urbana-Champaign
	  Naperville, IL			pjl@cs.uiuc.edu
Technical Details
Message-ID: <BxvtxB.CqA@cs.uiuc.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!gumby!wupost!cs.uiuc.edu!sparc0b!pjl
References: <Bxu3J4.F93@news.cso.uiuc.edu> <5225@holden.lulea.trab.se>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++
Path: arc1-ca.pugleaf.net!sparky!uunet!gumby!wupost!cs.uiuc.edu!sparc0b!pjl
From: pjl@cs.uiuc.edu (Paul Lucas)
Subject: Re: Recursive templates
Message-ID: <BxvtxB.CqA@cs.uiuc.edu>
Sender: news@cs.uiuc.edu
Organization: University of Illinois at Urbana-Champaign
References: <Bxu3J4.F93@news.cso.uiuc.edu> <5225@holden.lulea.trab.se>
Date: Tue, 17 Nov 1992 22:46:23 GMT
Lines: 55