🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

overloading templates

#1005
From: David Cok
Date: Thu, 04 Apr 1991 11:45
44 lines
1936 bytes
Will someone privy to the ANSI discussions on templates answer this for me?:

Is it expected that class template definitions will be able to be overloaded
or have default arguments?  The ARM does not discuss this except to say that
"There must be exactly one definition for each template of a given name in a
program", which leads me to think the answer to my question is no.  However,
a template is basically a function which returns a class or a function (it
just has to be evaluated at compile-time), so one might think that it could
be overloaded like ordinary functions.

For example:
	template<class T> class Vector ...
			// defines a template for a Vector of T of arbitrary
			// and variable size
	template<class T, int size> class Vector ...
			// defines a template for a Vector of T of fixed size
			// some checks on sizes of vectors could be done at
			// compile-time

then
	Vector<int> a,b;
	Vector<int,10> c,d;
	Vector<int,20> e,f;

	...
	a+=b; // runtime check that sizes of vectors are the same
	c+=d; // ok, sizes match at compile-time
	c+=e; // compile-time type error -- no operation defined to add a
		// Vector<int,10> to a Vector<int,20>


Another example:

	template<class T,int size=100> class Stack ...
		// defines a Stack implemented on top of a fixed size array
		// with default size of 100

	Stack<int> a; // Stack of ints with size of 100
	Stack<int,200> b; // Stack of ints with size of 200


David R. Cok
Eastman Kodak Company -- Imaging Science Laboratory
cok@Kodak.COM
Technical Details
Message-ID: <1991Apr4.114557.17897@kodak.kodak.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!asuvax!ncar!gatech!udel!rochester!kodak!islsun!cok

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!asuvax!ncar!gatech!udel!rochester!kodak!islsun!cok
From: cok@islsun.Kodak.COM (David Cok)
Newsgroups: comp.std.c++
Subject: overloading templates
Message-ID: <1991Apr4.114557.17897@kodak.kodak.com>
Date: 4 Apr 91 11:45:57 GMT
Sender: cok@Kodak.COM
Organization: Eastman Kodak Co., Rochester, NY
Lines: 44