How to avoid variable capturing in `foreach` loop with lambdas?

thebluepandabear therealbluepandabear at protonmail.com
Thu Jan 5 13:05:46 UTC 2023


Update some time later: the only way (oof!) around this seems to 
be using a `static foreach` with arrays:

```D
Button[3] b;

static foreach (indx, BoardSize boardSize; arr) {
     b[indx] = new Button();
     b[indx].text = format("%sx%s", boardSize[0], boardSize[1]);
     b[indx].onButtonClick = {
         
eventHandler.settingsWindow_onBoardSizeButtonClick(boardSize);
     };
     _boardSizeRow.addChild(b[indx]);
}
```

Any other ways of fixing this annoying issue?




More information about the Digitalmars-d-learn mailing list