typedef: what's it good for?
grauzone
none at example.net
Wed Nov 11 09:04:45 PST 2009
Walter Bright wrote:
> 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?
One _actual_ use of typeof is to force a different array initializer
(for performance reasons):
typedef int Foo = 1;
Foo[] arr;
arr.length = 567;
//with int[] arr, you now had to do arr[] = 1;
Also, you can easily define new exception classes:
//no need to write a ctor which just calls the super ctor
typedef Exception MyException;
But these are just symptoms of other problems of the language.
Can typedef be the same as alias, if the current functionality goes?
More information about the Digitalmars-d
mailing list