Re: array depth template

2009-06-11 Thread Saaa
>Um, there's no "one's better than the other." Don't overgeneralize on things you don't understand. Implicit conversion is necessary in some cases, and in others, exact comparison is needed. I didn't mean it like that, don't worry :) I mean, I apparently used implicit when I actually wanted ex

Re: array depth template

2009-06-11 Thread Saaa
> > Your template. Types are not values, you cannot declare a constant > that is a type. You have to use alias instead: > > template BaseType(T: T[]) { alias BaseType!(T) BaseType; } > template BaseType(T) { alias T BaseType; } Erm, why did this print corretly? writefln(`BaseType = `, BaseType!

Re: array depth template

2009-06-11 Thread Jarrett Billingsley
On Thu, Jun 11, 2009 at 11:45 PM, Saaa wrote: >> I'm.. not sure, in this case anyway.  Normally == does strict type >> comparison while : does implicit type conversion, but in this case, >> is() is being (ab)used to pick apart a type rather than test one.  I >> think it'll always return 'true' in

Re: array depth template

2009-06-11 Thread Jarrett Billingsley
On Fri, Jun 12, 2009 at 12:04 AM, Saaa wrote: >> >> template BaseType(T: T[]) { const BaseType = BaseType!(T); } >> template BaseType(T) {const BaseType = T; } > > .. > else static if( std2.traits.isNumeric!( BaseType!(T) ) ) > { > .. > > ddata\ddata.d(192): template instance isNumeric!(int) does n

Re: array depth template

2009-06-11 Thread Saaa
> > template BaseType(T: T[]) { const BaseType = BaseType!(T); } > template BaseType(T) {const BaseType = T; } .. else static if( std2.traits.isNumeric!( BaseType!(T) ) ) { .. ddata\ddata.d(192): template instance isNumeric!(int) does not match any template declaration ddata\ddata.d(192): Error:

Re: array depth template

2009-06-11 Thread Saaa
> 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. Although I do

Re: array depth template

2009-06-11 Thread Saaa
>> Any advantage to using two? > > I just tend to prefer template specialization when doing type pattern > matching. It works out better than is() in some cases. Looks very Haskell like :) > >> He also does : is( T B ==B[]) iso is( T B:B[] ) >> Any significant difference there? > > I'm.. not su

Re: array depth template

2009-06-11 Thread Jarrett Billingsley
On Thu, Jun 11, 2009 at 11:02 PM, Saaa wrote: > Any advantage to using two? I just tend to prefer template specialization when doing type pattern matching. It works out better than is() in some cases. > He also does : is( T B ==B[]) iso is( T B:B[] ) > Any significant difference there? I'm..

Re: array depth template

2009-06-11 Thread Saaa
Also, what's the advantage of explicitly defining it as a template?

Re: array depth template

2009-06-11 Thread Saaa
> > 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. Ah , that's

Re: array depth template

2009-06-11 Thread Jarrett Billingsley
On Thu, Jun 11, 2009 at 9:15 PM, Saaa 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

Re: array depth template

2009-06-11 Thread BCS
Hello Saaa, 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; } I just posted this today http://www.dsource.org/projects/scrapple/browser/trunk/Serial/utill.d

array depth template

2009-06-11 Thread Saaa
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; }