Is this a feature?

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jan 21 06:39:43 PST 2016


On Thursday, 21 January 2016 at 14:35:09 UTC, Sebastiaan Koppe 
wrote:
> 	static if (!is(SomethingUndefined!moreUndefined[0] : 
> UndefinedThing))


Yes, the is expression returns false for undefined things because 
they aren't types. The standard library uses this in a lot of 
places to test for undefined functions, like checking for 
features in ranges. (The is expression has been around a lot 
longer than __traits btw)

Here's the relevant spec link:

http://dlang.org/spec/expression.html#IsExpression

"Type is the type being tested. It must be syntactically correct, 
but it need not be semantically correct. If it is not 
semantically correct, the condition is not satisfied. "

syntax is forming valid *looking* names and expressions, etc.

semantically correct means passing name lookups and other tests 
that require the compiler to understand the context.

It says it needs to look right, but not necessarily anything more.


More information about the Digitalmars-d-learn mailing list