opApply and attributes

solidstate1991 laszloszeremi at outlook.com
Tue Jul 7 00:20:40 UTC 2020


See implementation of data structure here: 
https://github.com/ZILtoid1991/collections-d/blob/master/source/collections/treemap.d#L565

If I try to compile this code, it'll fail, limiting it's usecase:

@safe pure unittest {
	alias IntMap = TreeMap!(int, int, false);
	IntMap test;
	test[5] = 5;
	test[7] = 7;
	test[3] = 3;
	foreach(elem, key; test) {
		assert(elem == key);
	}
}

I know that implementing foreach with other means do exist, and I 
used them in my other data structures, but it's much more 
difficult (and potentially slower) to implement that within a 
binary search tree.

Should I change the `opApply` into the `popfront` - `front` - 
`empty` trinity, or write a template that overrides all the 
potential attribute combinations?

Maybe D needs a template for attributes somehow, or something 
like that.


More information about the Digitalmars-d-learn mailing list