mixin template TypeDef(Type, string name, Type init) { mixin(`struct `~name~` { public alias _impl this; private Type _impl = init; };`); }
unittest { mixin TypeDef!(int, `MyInt`, 5); MyInt mi; assert(typeid(myInt) != typeid(int)); assert(mi == 5); } On Sat, May 5, 2012 at 3:09 PM, bearophile <bearophileh...@lycos.com> wrote: > Mehrdad: > >> Now it's impossible to figure out whether a ParameterTypeTuple contains an >> HWND versus an HGDIOBJ or whatever... >> >> this should really be fixed... > > > typedef is a quite useful feature, but the one present in D was > unsound/broken, especially in presence of OOP. Fixing language features is > hard (people didn't seem to understand that typedef is not meant to be used > with classes), once their semantics is defined, it's quite hard to fix it. > But adding features to D/Phobos is much simpler. So once there is a clear > and sound design for what this feature has to do and its semantics, I expect > to see in D a way to do the same things. Currently the Typedef in Phobos is > more broken than the built-in typedef. Here the Ada language is a good > reference to copy from. So the idea of removing typedef was good iff we > eventually have something good to replace it. > > Bye, > bearophile -- Bye, Gor Gyolchanyan.