Making alias of a struct field needs "this".
Steven Schveighoffer
schveiguy at gmail.com
Tue Jun 2 20:38:40 UTC 2020
On 6/2/20 10:51 AM, realhet wrote:
> On Tuesday, 2 June 2020 at 13:10:55 UTC, Paul Backus wrote:
>> On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote:
>> mixin("@property auto ", k, "() const { return ", v, "; }");
>
> Wow, string mixin can process comma separated list, I gotta remember
> this, thanks!
Indeed, I too did not know about this!
I generally do a ~ b ~ c, not worrying about performance since it's
compile time, but this requires that you do the conversion to string
yourself. In some cases, it's a requirement since what the compiler does
to convert to a string may not be what you want.
But something like mixin("int a = ", adefault, ";"); is much better than
import std.format;
mixin(format("int a = %s;" adefault));
I will have to remember this. I recently found out that pragma(msg) has
the same capability.
-Steve
More information about the Digitalmars-d-learn
mailing list