July 01, 2008
Manfred Nowak wrote:
> janderson wrote:
> 
>> You need a stopping condition like template specialization or an static if.
> 
> ... but if this is true, then I have to implement a stopping condition or a static if for _every possible_ actual type ( int, uint, ...)---and the generic achievenment is lost.
> 
> -manfred 
> 

ic,

What about calling another template?

class A(T){
  ...
}

class C(T){
  pragma( msg, Format!(is(T:C!(A!(int)))));
}

Although I'm not exactly sure what your trying to do.



-Joel
July 01, 2008
JAnderson wrote:
> Manfred Nowak wrote:
>> janderson wrote:
>>
>>> You need a stopping condition like template specialization or an static if.
>>
>> ... but if this is true, then I have to implement a stopping condition or a static if for _every possible_ actual type ( int, uint, ...)---and the generic achievenment is lost.
>>
>> -manfred
> 
> ic,
> 
> What about calling another template?
> 
> class A(T){
>   ...
> }
> 
> class C(T){
>   pragma( msg, Format!(is(T:C!(A!(int)))));
> }
> 
> Although I'm not exactly sure what your trying to do.
> 
> 
> 
> -Joel

There's also typeof(this).

-Joel
July 02, 2008
On 2008-06-30 21:53:40 +0200, "Manfred_Nowak" <svv1999@hotmail.com> said:

> Michel Fortin wrote:
> 
>> You could add a dummy member in C!(T) and check for its presence.
> 
> Yes. That seems to be less hackish than what Robert suggested. But
> still no possibility to fetch a non trivial depth of recursion.

I simply use two templates, one to give me the depth of recursion, one to give the base type...

This is for arrays, but it can be adapted also for other types

/// Strips the []'s off of a type.
template arrayBaseT(T)
{
   static if( is( T S : S[]) ) {
       alias arrayBaseT!(S)  arrayBaseT;
   }
   else {
       alias T arrayBaseT;
   }
}

/// Count the []'s on an array type
template arrayRank(T) {
   static if(is(T S : S[])) {
       const uint arrayRank = 1 + arrayRank!(S);
   } else {
       const uint arrayRank = 0;
   }
}

Fawzi

1 2
Next ›   Last »