www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - should 'template MyT (T : Object)' match interface-types?

I'm making an all-purpose isType!(AnyType)(anything) predicate and I encountered
interface-types not matching my 'template isType (T : Object)' which is going to
make it more complex... so I was wondering if interface-types shouldn't be
matching (T : Object)?

I.E.:

: import std.stdio;
:
: template MyT (T : Object)
: {
:     void MyT (Object o)
:     {
:         writefln("MyT!(T:Object)");
:         writefln("typeid(T) : ", typeid(T));
:         writefln("typeid(T) is a TypeInfo_Class : ", 
:             (cast(TypeInfo_Class) typeid(T)) ? true : false);
:     }
: }
:
:
: template MyT (T)
: {
:     void MyT (Object o)
:     {
:         writefln("MyT!(T) ...not what I wanted");
:         writefln("typeid(T) : ", typeid(T));
:         writefln("typeid(T) is a TypeInfo_Class : ", 
:             (cast(TypeInfo_Class) typeid(T)) ? true : false);
:     }
: }
:
:
: interface MyInterface {}
: class MyClass : MyInterface {}
:
:
: void main ()
: {
:     MyClass c = new MyClass;
:
:     MyT!(MyClass)(c);
:     writefln();
:     MyT!(MyInterface)(c);
: }

$ ./tmpl_intf
MyT!(T:Object)
typeid(T) : MyClass
typeid(T) is a TypeInfo_Class : true

MyT!(T) ...not what I wanted
typeid(T) : MyInterface
typeid(T) is a TypeInfo_Class : true
Jun 04 2005