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

rkompass rkompass at gmx.de
Mon Mar 18 08:38:51 UTC 2024


To solve the problem with the 1-variable and 2-variable versions 
of foreach I
tried opApply and found that the compiler prefers it over opSlice 
and opIndex() (the latter without argument).

My code:

```d
	int opApply(int delegate(Variant) foreachblock) const {
		int result = 0;
		foreach(val; dct) {
			result = foreachblock(val);
			if (result)
				break;
			}
		return result;
	}
	int opApply(int delegate(Variant, Variant) foreachblock) const {
		int result = 0;
		foreach(key, val; dct) {
			result = foreachblock(key, val);
			if (result)
				break;
		}
		return result;
	}
```
So I'm fine with this now.




More information about the Digitalmars-d-learn mailing list