How can I test at compile time whether T is an instance of an interface ?

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Sep 23 18:50:28 UTC 2020


Try this:

	interface I {}
	class C : I {}
	class D {}
	struct S {}

	pragma(msg, is(C : I));	// true
	pragma(msg, is(D : I));	// false
	pragma(msg, is(S : I));	// false

So probably what you want is something like this:

	void register(C, ARGS...)(ARGS args)
		if (behavesLikeFoo!C || is(C : IFoo))
		...


T

-- 
Change is inevitable, except from a vending machine.


More information about the Digitalmars-d-learn mailing list