home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!stanford.edu!EE.Stanford.EDU!sierra!mcgrant
- From: mcgrant@gomez.stanford.edu (Michael C. Grant)
- Subject: Re: template disappointments ... (suggestions?
- In-Reply-To: cflatter@nrao.edu's message of Tue, 29 Dec 1992 20:44:31 GMT
- Message-ID: <MCGRANT.92Dec29191250@gomez.stanford.edu>
- Sender: usenet@EE.Stanford.EDU (Usenet)
- Organization: Information Systems Laboratory, Stanford University
- References: <DSCHIEB.92Dec29133556@muse.cv.nrao.edu> <1992Dec29.204431.13413@nrao.edu>
- Date: 29 Dec 92 19:12:50
- Lines: 59
-
-
- In article <1992Dec29.204431.13413@nrao.edu>
- cflatter@nrao.edu (Chris Flatters) writes:
- In article 92Dec29133556@muse.cv.nrao.edu,
- dschieb@muse.cv.nrao.edu (Darrell Schiebel) writes:
- > (1) The inability to derive templated classes from a non-templated
- > base class of the same name:
- > class typeinfo {};
- > template<class t> class typeinfo : public typeinfo {};
- Yeah, that's a bummer. I see no reason why typeinfo and typeinfo<T>
- can't be distinguished by any reasonable compiler.
-
- This is according to the ARM:
-
- A class template name must be unique in the program and may not
- be declared to refer to any other template, class, function,
- object, value, or type in the same scope.
- [p343]
- What's yer point? That's why this is called 'template disappointments.'
-
- Here are mine, both of which I've mentioned before, but nobody has managed
- to convince me it can be simulated in the current language.
-
- (1) Templated member functions. Someone gave me some lame argument that
- since you can specialize any templated function you can break into
- the private structure of a class, but since there are so many easy
- ways to do that already I don't accept that argument.
- (2) A compile-type typeof() operator like GNU's that can be used in
- templates.
-
- For example:
-
- double abs(double);
- double abs(const complex&);
-
- template <class T> foo {
- T data;
- typeof(abs(T)) norm;
- ...
- }
-
- I suppose I wouldn't mind faking it like this if necessary
- (and, of course, if it's possible).
-
- template <class T> typedef T normType<T>;
- typedef double normType<complex>;
-
- template <class T> foo {
- T data;
- normType<T> norm;
- ...
- }
-
- But this is hardly elegant! The typeof() operator would be nicer.
-
- Michael C. Grant
-
- --
- "Long hair, short hair--what's the difference once the head's blowed off?" (?)
-