On Sunday, 9 February 2020 at 00:57:05 UTC, realhet wrote:
On Sunday, 9 February 2020 at 00:41:12 UTC, realhet wrote:
On Sunday, 9 February 2020 at 00:27:21 UTC, Adam D. Ruppe wrote:


    mixin([FieldNameTuple!T].map!(n => n~"=(new T)."~n~";").join);

After checking it in the asm debugger, it turned out, that it evaluates (new T) in runtime. (Silly me, because the constructor can have side effects.) So I first put the default values into an enum, and then do the assignment:

    foreach(n; FieldNameTuple!T){{
      mixin("enum def = (new T).@; @ = def;".replace("@", n));
    }}

And that became as fast as it can be:

    mov dword ptr ds:[rax+10], 2A

Thanks for the help again.

Reply via email to