On Fri, Aug 01, 2014 at 02:20:53PM +0000, "Nordlöw" via Digitalmars-d-learn wrote: [...] > What is the preffered (fast) way to check at compile-time if an > instance x of a type T can be used *either* as > > f(x) > > or > > x.f?
if (is(typeof(f(x))) || is(typeof(x.f))) Basically, is(X) checks if X has a valid type (which include void if f doesn't return anything), and typeof(Y) returns the type of Y if it exists, otherwise it is an error and has no type. So if f(x) doesn't compile, then typeof(f(x)) has no type, and so is(typeof(f(x))) will be false. Ditto for x.f. T -- All men are mortal. Socrates is mortal. Therefore all men are Socrates.