bearophile Wrote: > Justin Johansson Wrote: > > > Bingo. I'm sure there would be a huge benefit to be able to distinguish > > string or any primitive type > > in such manner without having to invent a Filename class, AbsolutePathName > > class etc. > > Can D typedef be used for such purpose? > > Bye, > bearophile
Yes it can to a degree. It is useful and a little type-safe smarter than its C counterpart going by the few D tests that I've done on my journey into the language. Drawback, as far as I can tell, is the lack of a constructor for typedef'ed values. Seems like you need to synthesise a typedef'ed value with a function that casts it to the typedef type from a primitive type inside the function and return the casted result. Otherwise, reminiscent of leaky fountain pens of yesteryear, you can blot casts all over your code. I may be wrong; there may be a better way in D. Doesn't C++ allow you to construct primitive values in syntax similar to a function call, e.g. int(20); Whether same works for typedef types in C++ I cannot recall just right now. Ciao Justin
