On Thu, Jun 11, 2009 at 9:15 PM, Saaa<em...@needmail.com> wrote: > Is this a good way to get the depth of an array? > > int getArrayDepth(T)(ref T array) > { > static if( is(T A:A[]) ) > { > A arr; > return 1 + getArrayDepth(arr); > } > else > { > return 0; > } > return -1; > }
It's kind of the right idea, but.. it's also kind of weird. template ArrayDepth(T: T[]) { const ArrayDepth = 1 + ArrayDepth!(T); } template ArrayDepth(T) { const ArrayDepth = 0; } This lets you get the depth of any array _type_, like ArrayDepth!(int[][]) gives 2.