issue with static foreach

Patrick Schluter Patrick.Schluter at bbox.fr
Thu Jul 22 08:16:43 UTC 2021


On Thursday, 22 July 2021 at 03:43:44 UTC, someone wrote:
> ```
>
> Now, if uncomment those two innocuous commented lines for the 
> if (true == true) block:
>
> ```d
>
> labelSwitch: switch (lstrExchangeID) {
>
> static foreach (sstrExchangeID; gstrExchangeIDs) {
>
>    mixin(r"case r"d, `"`, sstrExchangeID, `"`, r"d : "d);
>    mixin(r"classTickerCustom"d, sstrExchangeID, r" 
> lobjTicker"d, sstrExchangeID, r" = new classTickerCustom"d, 
> sstrExchangeID, r"(lstrSymbolID);"d);
>    mixin(r"if (true == true) {"d);
>    mixin(r"pobjTickersCustom"d, sstrExchangeID, r" ~= 
> lobjTicker"d, sstrExchangeID, r";"d);
>    mixin(r"pobjTickersCommon ~= cast(classTickerCommon) 
> lobjTicker"d, sstrExchangeID, r";"d);
>    mixin(r"}"d);
>    mixin(r"break labelSwitch;"d);
>
> }
>
> default :
>
>    break;
>
> }

What an unreadable mess. Sorry.

I would have done something like that:


```d
mixin(format!
     `case r"%1$s"d :
        classTickerCustom%1$s  lobjTicker%1$s  = new 
classTickerCustom%1$s (lstrSymbolID);
        if (true == true) {
            pobjTickersCustom%1$s  ~= lobjTicker%1$s ;
            pobjTickersCommon ~= cast(classTickerCommon) 
lobjTicker%1$s ;
        }
        break labelSwitch;`(sstrExchangeID)
);
```

That's easier to edit imho.



More information about the Digitalmars-d-learn mailing list