On Wednesday, 1 January 2014 at 01:55:19 UTC, Adam D. Ruppe wrote:
On Wednesday, 1 January 2014 at 01:33:04 UTC, Frustrated wrote:
But your template mixin is still duplicating generic code that should be easily handled automatically. (Generic properties are just wrappers around private fields that always have the same code (just return or set the field))

Oh yeah, that can be done too.

Here's an example:
http://arsdnet.net/dcode/autoimpl.d

The mixin template is implemented by a helper function, which loops over the interface methods and builds a code string for it. It doesn't handle complex cases, like a setter without a getter, but it is a start.

The pragma(msg) in there shows you the generated code when it compiles, which can help debugging or just show you what's going on, of course you can remove that when you're happy with it.

This doesn't quite work(at least for me) and seems unstable.
Doesn't get all the attributes(what if you have a safe property?
And doesn't get methods. It is a start though....

Reply via email to