Oops! Stupid of me. There were three bugs in the code.
Correct code is as follow: import std.stdio; class Data { string m = "Hello world !"; } struct IdxElem(D) { bool inUse; D data; } IdxElem!(Data)[string] idx; void main() { idx["test1"] = IdxElem!Data(true, new Data); idx["test2"] = IdxElem!Data(false, new Data); writeln(idx["test2"].data.m); writeln("Hello world!"); }