www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is this a feature?

reply Sebastiaan Koppe <mail skoppe.eu> writes:
module undefined;

unittest
{
	static if (!is(SomethingUndefined!moreUndefined[0] : 
UndefinedThing))
	{
		pragma(msg,"This will compile just fine!");
	}
}
Jan 21
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
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
parent Sebastiaan Koppe <mail skoppe.eu> writes:
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:
 	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)
Thanks. I reckoned as much. Can be handy in places. But I just spend some time figuring out that I was missing an import...
Jan 21