On Friday, 30 August 2013 at 15:41:55 UTC, Namespace wrote:
I believe typedef was deprecated due to no-one being able to
agree on the semantics (although it's a bit before my time). I
think it needs to come back as a very simple concept:
A type duplication. e.g. typedef int myInt; (or typedef myInt
= int;) creates a new type that is exactly identical to int,
but is a distinct type in the type system.
It should provide *exactly* identical behaviour to e.g. having
two structs with identical contents but different names. E.g.
struct A{}
typedef A tA;
alias A aA;
alias tA atA;
typedef aA taA;
assert(!is(tA == A));
assert(is(aA == A));
assert(is(atA == tA));
assert(!is(taA == atA));
etc....
It's a really basic feature that D ought to have.
I don't understand the difference to alias myInt = int;
Isn't it the same?
see the first 2 asserts. alias doesn't create a new type, it just
creates a new identifier for the old type.
A rough analogy: alias is by reference and typedef is by value