Kisses Ary: It seems you can't mixin cases separately, you need to mixin the whole switch (bug?)
string CasesString(int depth) { string res; res ~= `switch( depth ){`; for (int i = 0; i < depth; ++i) { res ~= `case `~ctToString(i)~`:`~ ` if( temp`~ indexString(i) ~`.length < index[`~ctToString(i)~`] ) temp`~ indexString(i) ~`.length = temp`~ indexString(i) ~`.length * 2 ;`~ `break;`; } res ~= `default:assert(false);break;}`; return res; } mixin ( CasesString(Depth!(T)) );