🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: typedef typename

#1671
From: John Max Skaller
Date: Tue, 08 Aug 1995 11:03
50 lines
2073 bytes
In article <1995Jul19.120503.13951@leeds.ac.uk>,
Gary Thompson <garyt@resumix.portal.com> wrote:
>The only question I wanted to ask about the putative standard is why there is still no provision for creating a new type.
...
>typedef long miles;
>typedef long kilometers;
>typedef long yards;

	I guess this is because the world of C hackery is concerned
with efficiency and not safety. 

	The opposite viewpoint is that this solution is very specific
and thus quite weak, and so isn't worth an extension.

	You _can_ hack a solution if you design your own types
with this in mind. For example:

	template<class T> class C { .. ordinary class here .. };
	enum X {};
	enum Y {};
	C<X> cx;
	C<Y> cy; // structurally equivalent but distinct types

Of course, this doesn't work for built-in types and can be
a hassle to retrofit. I'm not sure how many compilers would be smart
enough to recognize the same binary object code can be used for
both classes.

This problem is quite serious in scientific programming where,
for example, one want to avoid mistakes with matrices operating
with different bases on the same space, or even on distinct spaces.

See Barton and Nackman for more information on how to design
this kind of thing into your classes systematically.

BTW: a hack that may work in future is:

	namespace Metres {
		#include "number.stuff"
	}
	namespace Feet {
		#include "number stuff"
	}
	// :-))

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
	Maxtal Pty Ltd,		    
        81A Glebe Point Rd, GLEBE   Mem: SA IT/9/22,SC22/WG21 
        NSW 2037, AUSTRALIA	    Phone: 61-2-566-2189
Technical Details
Message-ID: <407gaa$67d@metro.ucc.su.OZ.AU>
Path: arc1-ca.pugleaf.net!news.cs.su.oz.au!metro!news
References: <1995Jul19.120503.13951@leeds.ac.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.cs.su.oz.au!metro!news
From: maxtal@Physics.usyd.edu.au (John Max Skaller)
Newsgroups: comp.std.c++
Subject: Re: typedef typename
Date: 8 Aug 1995 11:03:38 GMT
Organization: School of Physics, University of Sydney, Australia
Distribution: inet
Message-ID: <407gaa$67d@metro.ucc.su.OZ.AU>
References: <1995Jul19.120503.13951@leeds.ac.uk>
NNTP-Posting-Host: physics.su.oz.au