typedef: what's it good for?

BCS none at anon.com
Tue Nov 10 22:45:26 PST 2009


Hello Walter,

> When I originally worked out ideas for D, there were many requests
> from the C and C++ community for a 'strong' typedef, and so I put one
> in D. I didn't think about it too much, just assumed that it was a
> good idea.
> 
> Now I'm not so sure. Maybe it should be removed for D2.
> 
> Does anyone use typedef's?
> 
> What do you use them for?
> 
> Do you need them?
> 

I'd use them more if they were stronger. particularly, I'd love it if they 
could be used to add/overide stuff basic types:

typedef int TD
{
   TD opAdd(TD that) { assert(this < that); return cast(int)this + cast(int)that; 
}
   ...
}

or even better

typedef int TD(T)
{
   TD!(T) opAdd(TD!(T) that) if (Pred!(T)) = default; // use the default 
but restrict the operation
   ...
}





More information about the Digitalmars-d mailing list