C++ std::map equivalent? (An in-order iterable associative container)
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun May 4 15:03:47 PDT 2014
Mark Isaacson:
> Got it, no native support. Most unfortunate.
What native support are you talking about?
> I've always been vehemently against losing self-documentation
> via the std::pair/tuple based solution to the problem.
What self documentation are you losing in D?
> I ended up rolling my own solution that lets you give
> meaningful names to the wrapper struct's data members:
> http://pastebin.com/cKLccqFn
What's bad about this?
void main() {
import std.stdio, std.container, std.typecons;
alias Two = Tuple!(string,"str", int, "bob");
alias MyTree = RedBlackTree!(Two, q{a.str < b.str}, false);
auto map = new MyTree(Two("hello", 5), Two("zbd", 3),
Two("abc", 9));
map[].writeln;
auto rng = map[];
assert(rng.front == map.Elem("abc", 9));
assert(rng.front.str == "abc");
assert(rng.front.bob == 9);
}
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list