How to iterate over const(RedBlackTree)?
monarch_dodra
monarchdodra at gmail.com
Thu Jan 2 05:30:05 PST 2014
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".
More information about the Digitalmars-d
mailing list