Is remove safe using foreach

lili lilijreey at 126.com
Mon Dec 12 17:23:36 UTC 2022


```
int[string] aa = ["ok":1, "aaa":2, "ccc":3, "ddd":4];
	foreach (k ; aa.byKey)
	{
		if (k == "aaa") {
		aa.remove(k);
		aa["ww"] = 33;
		}

		if (k == "ww") {
		aa.remove(k);
		aa["vv"] = 33;
		}
	}

writeln(aa); // output ["ok":1, "ddd":4, "vv":33, "ccc":3] is ok
```



More information about the Digitalmars-d-learn mailing list