auto d = dict!(string, string)(); scope(exit) d.free(); d["Hell"] = "No"; d["Hello"] = "World"; d["Help"] = "Me"; d["Something"] = "Else"; assert(d["Hell"] == "No"); assert(d["Hello"] == "World"); assert(d["Help"] == "Me"); assert(d["Something"] == "Else"); assert("Held" !in d); assert(d.length == 4); string[string] elements; foreach(key, value; d) { elements[key] = value; } assert(elements["Hell"] == "No"); assert(elements["Hello"] == "World"); assert(elements["Help"] == "Me"); assert(elements["Something"] == "Else"); assert(elements.length == d.length); d["Something"] = "New"; assert(d["Something"] == "New"); d.remove("Hell"); assert(d.length == 3); assert(d.get("Hell") is null); d.clear(); assert(d.length == 0); assert("Hello" !in d); assert("Help" !in d); assert("Something" !in d); d["Held"] = "Fire"; assert(d["Held"] == "Fire"); auto di = dict!(string, int); scope(exit) di.free(); di[0xBEAF] = "BEAF"; di[0xDEADBEAF] = "DEADBEAF"; di[0xDEAD] = "DEAD"; assert(di[0xBEAF] == "BEAF"); assert(di[0xDEADBEAF] == "DEADBEAF"); assert(di[0xDEAD] == "DEAD");
Convenient function for dict creation.