How is std.traits.isInstanceOf supposed to work?

Tommi tommitissari at hotmail.com
Sun Nov 10 15:21:57 PST 2013


The documentation says:

template isInstanceOf(alias S, T)
---------------------------
Returns true if T is an instance of the template S.

But, is isInstanceOf supposed to return true if T is a subtype of 
an instance of the template S ? (but is not an instance of the 
template S). Currently it does return true if T is a struct, and 
doesn't if it's a class:

import std.traits;

struct SuperSt(T, int size)
{}

struct SubSt
{
     SuperSt!(short, 4) _super;
     alias _super this;
}

class SuperCl(T, U)
{}

class SubCl : SuperCl!(int, char)
{}

void main()
{
     static assert(isInstanceOf!(SuperSt, SubSt));
     static assert(!isInstanceOf!(SuperCl, SubCl));
}


More information about the Digitalmars-d mailing list