__traits(compiles,...) <=> ? is(typeof(...))

Philippe Sigaud philippe.sigaud at gmail.com
Mon Oct 29 03:58:37 PDT 2012


> Tell me please,in this code first and second static if,are these equivalent?
> with arg = 1, __traits(compiles,"check(arg);") = true,
> is(typeof(check(arg))) = false.

__traits(compiles, ...) takes an expression, not a string. From the
spec: "The arguments can be symbols, types, or expressions that are
syntactically correct. The arguments cannot be statements or
declarations."

(http://dlang.org/traits.html#compiles)

So, in your case, that would be:

__traits(compiles, {check(arg);})

Note that you can also use the type of arg:

__traits(compiles, {check(typeof(arg).init);})

or

is(typeof({ check(typeof(arg).init);})


More information about the Digitalmars-d-learn mailing list