Getting and using class hierarhy information in runtime

Uranuz neuranuz at gmail.com
Fri Feb 14 23:44:01 PST 2014


Also I have the following code but I get some error. I think it's 
because of std.algorithm.sort function that uses mixin to inject 
predcate. But it doesn't import symbols passed in predicate and 
fails. Is there some way of resolving this problem or I need to 
inject full code of function inside predicate?


import std.stdio, std.algorithm;

class A: Exception { this(){ super(null); } }

class B: A {}

class C: B {}

class D: A {}

class E: A {}

class F: E {}

size_t countDerivations(TypeInfo_Class typeinfo)
{	
	size_t result;
	while(typeinfo !is null)
	{	//writeln(typeinfo.name);
		result ++;
		typeinfo = typeinfo.base;
	}
	return result;
}

void main()
{
	
	auto typeinfo = typeid(C);
	//while(typeinfo !is typeid(Throwable))
	//{	writeln(typeinfo.name);
	//	typeinfo = typeinfo.base;
	//}
	
	auto list = [ typeid(C), typeid(B), typeid(A), typeid(F) ];
	
	
	//writeln( countDerivations( typeid(C) ) );
	
	auto sortedList = sort!("countDerivations(a) > 
countDerivations(b)")( list );
	writeln(sortedList);
}


More information about the Digitalmars-d-learn mailing list