On 2012-03-09 16:15:30 +0000, Andrei Alexandrescu <seewebsiteforem...@erdani.org> said:

I think a good approach in D would be to define mixins that work in conjunction with the feature involved, for example:

class A {
     int thing;
     mixin(DoNotSerialize!"thing");
     ...
}

or together:

class A {
     mixin(DoNotSerialize!(int, "thing"));
     ...
}

It's ugly, but it works… only to a point though. Try to annotate overloaded functions and it'll become a mess: either you duplicate the function name and all the argument types for each function, or you wrap the whole function body in the mixin.

If you need to annotate a struct or a class you'll have the same problem, just at a bigger scale. And it gets worse if you want to annotate templated types and functions: how can the attribute apply to each instance?

I'm not saying any of this is impossible using mixins, just that it becomes impractical as you go beyond the most simple cases.

--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/

Reply via email to