The following code passes both checks with dmd v2.067-devel-c6cf84f. I would expect the second one to fail:
import std.traits;
struct Foo(T)
{}
void main()
{
static assert(isInstanceOf!(Foo, Foo!int)); // OK
static assert(isInstanceOf!(Foo!int, Foo!int)); // ?
}
After debugging this issue I think that this is actually a dmd bug because variadic template argument deduction seems to be making an error. Here is the implementation of isInstanceOf:
enum bool isInstanceOf(alias S, T) = is(T == S!Args, Args...);
When both S and T are Foo!int, then (T == S!Args, Args...) should fail. (Actually, it could succeed only if Args... were resolved to be empty, which is not the case.)
The following code demonstrates that Args is non-empty when the S and T template arguments are both Foo!int.
struct Foo(T)
{}
bool dumpInformation(alias S, T, Args)()
{
import std.string;
pragma(msg, S); // prints: Foo!int
pragma(msg, T); // prints: Foo!int
pragma(msg, Args); // prints: int
return true;
}
// Copy of std.traits.isInstanceOf with the addition of dumpInformation()
enum bool myIsInstanceOf(alias S, T) =
is(T == S!Args, Args...) &&
dumpInformation!(S, T, Args)();
void main()
{
static assert(myIsInstanceOf!(Foo!int, Foo!int));
}
Ali