Regarding typedef
F. Almeida
francisco.m.almeida at gmail.com
Wed Aug 4 00:00:19 PDT 2010
>From what I understood, typedef is going to be replaced by a
templated structure and handle type conversion in that way.
This is understandable because 1) the keyword was easily confused
with C++ typedef, whose role was taken in D by alias (which is a
much less misleading keyword for what it does) and 2) as it was,
typedef was of questionable use (not being able to choose which
casts are permitted removed it of any practicality).
What I'm wondering is if it wouldn't have helped to enhance it
rather than simply remove it. Let us consider this hypothetical
syntax:
typedef MyType real : in(float,double,real), out(real);
It would read "MyType is mapped from real. Only a float, a double or
a real may cast to MyType. MyType may only cast to real." This would
allow all specified casts to be statically checked by the compiler.
Of course, one could also apply this syntax to structs or classes,
in which case the compiler could verify for existing opCast()() or
single-argument constructors between types, and reject the
definition otherwise. The shorter version:
typedef MyType real : float, double, real;
would mean that MyType accepts casts from the listed types, but may
not be cast to another type, and the simplest version:
typedef MyType real;
would be have the same meaning as the deprecated typedef statement.
What do you think?
More information about the Digitalmars-d
mailing list