On Thursday, 2 January 2014 at 11:23:39 UTC, Cooler wrote:
Example:
const RedBlackTree!int rbt = redBlackTree(1, 2, 3);
foreach(i; rbt[])
writeln(i);
dmd 2.064 give me error
"mutable method
std.container.RedBlackTree!int.RedBlackTree.opSlice is not
callable using a const object"
Without "const" keyword the example compiled and works fine.
How can I iterate over const?
Currently, this is not possible. Or if it was, it would have a
*very* high code cost inside RBT.
The issue is that *if* opSlice was marked as const, then the
returned range would also be const, and you can't iterate over
that :/ A solution might be possible, but the current "status
quo" is to not use const with ranges.
It's one of the "issues" with D-style qualification: It's "apples
all the way down".