typedef: what's it good for?
Adam D. Ruppe
destructionator at gmail.com
Wed Nov 11 09:34:05 PST 2009
On Wed, Nov 11, 2009 at 10:54:27AM -0600, Andrei Alexandrescu wrote:
> The last point was revealed by a conversation between Walter and me last
> night. I pointed out that typedef should create a *subtype* of a type, e.g.:
I was thinking about this a while ago and had a half baked proposal, but
ditched it exactly because it was half baked.
My thought was to have two kinds of typedef:
typedef int ID; // supertype
typedef ID : int; // subtype - the syntax is based on class inheritance
But I also kinda wanted no implicit conversion....
static typedef int ID; // :-P
But however it is created, it would be useful for completely opaque types -
useful for talking to C libraries. You can copy it, store it, and pass it
around, but nothing else.
> Subtype vs. supertype is only the beginning of problems. Consider some
> choice has been made, and then look at this orthogonal problem:
Disallow it. I don't think I've ever wanted to use typedef on anything
other than primitives (and void*) anyway - structs and classes have
their own ways to do the job.
--
Adam D. Ruppe
http://arsdnet.net
More information about the Digitalmars-d
mailing list