digitalmars.D.learn - Is this a feature?
- Sebastiaan Koppe (9/9) Jan 21 2016 module undefined;
- Adam D. Ruppe (16/18) Jan 21 2016 Yes, the is expression returns false for undefined things because
- Sebastiaan Koppe (3/12) Jan 21 2016 Thanks. I reckoned as much. Can be handy in places. But I just
module undefined; unittest { static if (!is(SomethingUndefined!moreUndefined[0] : UndefinedThing)) { pragma(msg,"This will compile just fine!"); } }
Jan 21 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.
Jan 21 2016
On Thursday, 21 January 2016 at 14:39:43 UTC, Adam D. Ruppe wrote:On Thursday, 21 January 2016 at 14:35:09 UTC, Sebastiaan Koppe wrote:Thanks. I reckoned as much. Can be handy in places. But I just spend some time figuring out that I was missing an import...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)
Jan 21 2016