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;
}
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
On Thu, Jun 11, 2009 at 9:15 PM, Saaaem...@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..
On Thu, Jun 11, 2009 at 11:02 PM, Saaaem...@needmail.com 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
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 sure, in this
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 don't
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:
On Fri, Jun 12, 2009 at 12:04 AM, Saaaem...@needmail.com 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)
On Thu, Jun 11, 2009 at 11:45 PM, Saaaem...@needmail.com 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
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 = `,
10 matches
Mail list logo