"macro" expansion to build switch case code
Paul
phshaffer at gmail.com
Mon Jul 3 22:06:06 UTC 2023
On Sunday, 2 July 2023 at 20:27:47 UTC, Steven Schveighoffer
wrote:
> On 7/2/23 1:02 PM, Paul wrote:
>> [...]
>
> Use a static foreach:
>
> ```d
> import std.traits; // for FieldNameTuple. there are other ways,
> but this is the most straightforward
> switchlabel: // this is needed for break inside a static foreach
> final switch(s) {
> static foreach(mem; FieldNameTuple!myS) {
> case mem ~ mem:
> __traits(getMember, this, mem) += n;
> break switchalbel;
> }
> }
> ```
>
> -Steve
Perfect. Thanks Steve!
More information about the Digitalmars-d-learn
mailing list