Test for self referential templated Class

janderson askme at me.com
Sun Jun 29 21:12:32 PDT 2008


Manfred Nowak wrote:
> Seems, that tests for the type of a self referential templated class 
> are impossible, because recursive expansion is forbidden.
> 
> Am I missing something?
> 
> Example:
> 
> import std.metastrings;
> class C(T){
>   pragma( msg, Format!(is(T:C!(int))));
>   //pragma( msg, Format!(is(T:C!(C!(int)))));  //recursive expansion 
> forbidden
> }
> void main(){
>   auto c1= new C!( C!(int));
>   auto c2= new C!( C!( C!(int)));
> }
> 
> -manfred

pragma( msg, Format!(is(T:C!(--> C!(int) <--- ))));  //recursive expansion

C!(int) will call itself forever.  You need a stopping condition like 
template specialization or an static if.



More information about the Digitalmars-d mailing list