A tutorial on D templates
Andrej Mitrovic
andrej.mitrovich at gmail.com
Mon Jan 16 03:43:49 PST 2012
On 1/15/12, Jacob Carlborg <doob at me.com> wrote:
> I'm not completely sure how it works but it
> looks like that Fields mixin can be replace with the code you have
> referenced from my Orange library and opDispatch.
You mean your `fieldsOf` template? I'm not really sure how that would
work, I've tried this:
This opBinary(string op)(This rhs)
{
This res;
foreach (field; fieldsOf!This)
{
mixin("res." ~ field ~ " = this." ~ field ~ op ~ " rhs." ~
field ~ ";");
}
return res;
}
But that gives me errors:
Error: variable __aggr901 cannot be read at compile time
Error: variable __aggr901 cannot be read at compile time
Error: variable __key902 cannot be read at compile time
Error: variable __aggr901 cannot be read at compile time
Error: variable __aggr901 cannot be read at compile time
Anyway that Fields mixin was something I wrote as a quick example for
the book. I've also tried using traits(allMembers), but that didn't
work too good.
More information about the Digitalmars-d-announce
mailing list