Creating ranges over mutable, const, or immutable data structures.

w0rp via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat May 24 10:02:25 PDT 2014


I have been writing my own hashmap which can provide forward 
ranges usable in @safe pure nothrow functions, because it's going 
to be useful for creating graph data structures with the same. I 
came to writing my ranges and I figured out how to do everything 
right for just mutable hashmaps, but I have no idea how to manage 
the tail-const nature of ranges in a variety of combinations. I 
figured out that I need to satisfy the following constraints.

Create a mutable KeyRange over a map which forwards on the right 
constness for the key type, so the following must be true.

HashMap!(K, V).keys.front -> K
const(HashMap!(K, V)).keys.front -> const(K)
immutable(HashMap!(K, V)).keys.front -> immutable(K)

I have encounted some difficulty in trying to write a range which 
does this.


More information about the Digitalmars-d-learn mailing list