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

Don Clugston dac at nospam.com
Tue Oct 30 00:37:51 PDT 2012


On 29/10/12 12:03, Jonathan M Davis wrote:
> On Monday, October 29, 2012 11:42:59 Zhenya wrote:
>> Hi!
>>
>> 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.
>
> In principle, is(typeof(code)) checks whether the code in there is
> syntatically and semantically valid but does _not_ check whether the code
> actually compiles. For instance, it checks for the existence of the symbols
> that you use in it, but it doesn't check whether you can actually use the
> symbol (e.g. it's private in another module).

Not even that. It checks if the expression has a type. That's all.
The expression has be syntactically valid or it won't compile at all. 
But inside is(typeof()) it is allowed to be semantically invalid.

I started using is(typeof()) as a check for compilability, and other 
people used the idea as well. But it only works if you can convert 
"compilable" into "has a type".


More information about the Digitalmars-d-learn mailing list