Please excuse me if my terminology is incorrect.
Is it possible to determine the value of a type argument in an instance of a class template in the D programming language?
Please consider the following class structure:
class Entity {
}
class User : Entity {
}
class Collection(E:Entity) {
}
class UsersCollection : Collection!(User) {
}
Now, having access to the "UsersCollection", I can determine that this is a subclass of Collection, but I want to determine what type of entity the collection is ("User")
Here are my experiments:
import std.traits;
int main(){
pragma(msg, BaseTypeTuple!UsersCollection);
pragma(msg, TransitiveBaseTypeTuple!UsersCollection);
pragma(msg, BaseClassesTuple!UsersCollection);
pragma(msg, UsersCollection);
pragma(msg, isInstanceOf!(Collection, UsersCollection));
foreach(BC; BaseClassesTuple!UsersCollection){
pragma(msg, BC);
pragma(msg, isInstanceOf!(Collection, BC));
}
return 0;
}
As you see the first BaseClassesTuple! UsersCollection is "Collection! (User)", but how to get "User" from it?
source
share