Making alias of a struct field needs "this".
Paul Backus
snarwin at gmail.com
Tue Jun 2 13:10:55 UTC 2020
On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote:
>
> static foreach(k, v; fieldMap){ mixin("@property auto $()
> const{ return #; }".replace("$", k).replace("#", v)); } //I
> know, i know -> AliasSeq :D
You can use std.format.format to do it in one function call:
mixin("@property auto %s() const { return %s; }".format(k,
v));
Or just put `k` and `v` directly into the mixin:
mixin("@property auto ", k, "() const { return ", v, "; }");
More information about the Digitalmars-d-learn
mailing list