Re: "macro" expansion to build switch case code

2023-07-03 Thread Paul via Digitalmars-d-learn
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 f

Re: "macro" expansion to build switch case code

2023-07-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/2/23 1:02 PM, Paul wrote: I have a struct similar to the following example.  I'd like to build an adder method without having to code the whole method. How do I use the D language to do this?  Template, mixins, CTFE..all of them? ```d struct myS {     int a, b, c, d, e, f, g, h, i;    

Re: "macro" expansion to build switch case code

2023-07-02 Thread kdevel via Digitalmars-d-learn
On Sunday, 2 July 2023 at 17:02:44 UTC, Paul wrote: I have a struct similar to the following example. I'd like to build an adder method without having to code the whole method. How do I use the D language to do this? Template, mixins, CTFE..all of them? ```d struct myS { int a, b, c, d

Re: "macro" expansion to build switch case code

2023-07-02 Thread nbdusr via Digitalmars-d-learn
On Sunday, 2 July 2023 at 17:02:44 UTC, Paul wrote: I have a struct similar to the following example. I'd like to build an adder method without having to code the whole method. How do I use the D language to do this? Template, mixins, CTFE..all of them? ```d struct myS { int a, b, c, d

"macro" expansion to build switch case code

2023-07-02 Thread Paul via Digitalmars-d-learn
I have a struct similar to the following example. I'd like to build an adder method without having to code the whole method. How do I use the D language to do this? Template, mixins, CTFE..all of them? ```d struct myS { int a, b, c, d, e, f, g, h, i; adder(string s, int n) {