Topic: a stronger typing non-synonomous typedef?
Author: dwalker07@snet.net.invalid (Daryle Walker)
Date: 1999/12/20 Raw View
<eljay@usa.net> wrote:
> I have a (frequently asked?) question: how can I make a robust C++
> typedef of an intrinsic (or a string, complex, or any
> class/struct/union) that is not merely an alias or synonym for the type,
> but a full fledged distinguished type? Whatever mechanism is proper
> should be a "no overhead, no loss of efficiency" solution.
[SNIP abstract example; screwed-up work-around using templates, macros,
and token pasting; and more specific reasons for this subtyping style.]
> The one answer I fear: use Ada.
Unfortunately, that is the answer. There isn't a way to make an
arbitrary type be like another type but non-synonymous. (The exception
is subclassing a struct/class type and adding no new members or methods,
and using the same set of constructors which pass their data onto the
matching base constructor.)
Is there a way to suggest this facility to the next version of C++? (I
think it may be too abstract to C.) Like Ada, there should be
non-synonomous types (NST) that are subtypes of a given type, and ones
that are completely seperate (just identical binary layouts). To
convert from one of these types to the original type or another of its
NSTs, an explicit static_cast should be done. However, implicit casts
from a NST subtype to its base type are allowed. All (or most) of the
support for NSTs can be done at compile-time, so why not allow this
abstraction? Remember, unlike regular class inheiritance, there is
never a binary data layout change with NSTs, and it can be applied to
any type.
--
Daryle Walker
Video Game, Mac, and Internet Junkie
dwalker07 AT snet DOT net
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]