Test for self referential templated Class

Manfred_Nowak svv1999 at hotmail.com
Mon Jun 30 12:53:40 PDT 2008


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.

import std.metastrings;
private typedef int TID; // TypeID for checking purposes
class C(T){
  alias .TID TID;
  pragma( msg, Format!(is( T.TID== TID)));
}
class D{
  private typedef int TID;
}
void main(){
  auto d= new C!( D);
  pragma( msg, "d done");
  auto c1= new C!(int);
  pragma( msg, "c1 done");
  auto c2= new C!( C!(int));
  pragma( msg, "c2 done");
  auto c3= new C!( C!( C!(int)));
  pragma( msg, "c3 done");
}

-manfred



More information about the Digitalmars-d mailing list