Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct KV(K, V, string keyName = "key", string valueName = "value") {
- mixin("K " ~ keyName ~ ";");
- mixin("V " ~ valueName ~ ";");
- bool opEquals()(auto const ref KV s) const {
- return mixin(keyName) == mixin("s." ~ keyName);
- }
- int opCmp(const ref KV s) const {
- return cmp(mixin(keyName), mixin("s." ~ keyName));
- }
- }
- auto createMap(K, V, alias less = "a < b", alias keyName = "key", alias valueName = "value", bool allowDups = false)() {
- return new RedBlackTree!(KV!(K, V, keyName, valueName), less, allowDups);
- }
- unittest {
- auto map = createMap!(string, int, "a < b", "str", "bob");
- map.stableInsert(map.Elem("hello", 5));
- map.stableInsert(map.Elem("zbd", 3));
- map.stableInsert(map.Elem("abc", 9));
- auto rng = map[];
- assert(rng.front == map.Elem("abc", 9));
- assert(rng.front.str == "abc");
- assert(rng.front.bob == 9);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement