spir wrote: (...) > > I like very much the template mixin solution. Would there be any > difference in inheriting an interface (or even a plain type)? Also, can > one presently rewrite this in D without _string_ mixin inside the > template? (Else this solution is simply not acceptable for me: I'm > allergic to code in strings; but don't ask me why ;-) > > Denis > -- -- -- -- -- -- -- > vit esse estrany ☣ > > spir.wikidot.com
Compared to inheriting interfaces: - works with primitive and struct types - no dynamic polymorphism - no performance penalty, likely less code size You can do it without string mixins by explicitly writing the code the mixin automates. This should also work more or less, but I find it less clear: struct NewType(T, string typename) { alias T this; T base; @disable void opAssign(T) {} } The typename parameter is arbitrary here, just to create a seperate type for each possible value. It might as well be an integer. alias NewType!(int, "Position") Position; void func(Position position) { ... } or used directly: void func(Newtype!(int, "Position") position) { ... }