How to make a struct containing an associative array to deeply copy (for repeated usage in foreach) ?

rkompass rkompass at gmx.de
Fri Mar 15 09:03:25 UTC 2024


@Monkyyy: I adopted your solution, it is perfect.

I only have one problem left:

The foreach loop with associative arrays has two cases:

`foreach(key, val; arr)` and `foreach(x; arr)`.
In the second case only the values are iterated.
With the present solution the iteration delivers (key, val) 
tuples.

Can this somehow be detected by the opSlice or is there another 
overloading
construct to be applied for this?


Addition: I noted that in the best matching 
[docs](https://dlang.org/spec/operatoroverloading.html#slice) 
only *ordinary arrays* are covered. Your solution would make a 
very nice addition for the case of associative arrays there. I 
learn't a lot from it.
Should I do an improvement request somewhere?





More information about the Digitalmars-d-learn mailing list