Re: test if object is instance of class at compile time

2011-12-22 Thread Elvis Maehren
Vladimir Panteleev wrote: I believe that's what __traits(compiles, ...) is for: __traits(compiles, cast(T) o) is true even if the cast blows up in CTFE, so that doesn't work.

Re: test if object is instance of class at compile time

2011-12-22 Thread Timon Gehr
On 12/21/2011 09:15 PM, Elvis Maehren wrote: This works fine at runtime, but explodes in CTFE: --- bool isInstanceOf(T, O)(O o) { return (cast(T) o) !is null; } --- CTFE doesn't like !is null (cannot compare [...] at compile time). This will be fixed in the next release:

Re: test if object is instance of class at compile time

2011-12-22 Thread Trass3r
I'd really like to have 'if (instance is ClassType)' syntax in D.

Re: test if object is instance of class at compile time

2011-12-22 Thread Andrew Wiley
On Thu, Dec 22, 2011 at 8:35 AM, Trass3r u...@known.com wrote: I'd really like to have 'if (instance is ClassType)' syntax in D. It couldn't use that syntax because 'is' means direct bitwise equality everywhere else. Changing it in this one situation would be awkward.

test if object is instance of class at compile time

2011-12-21 Thread Elvis Maehren
This works fine at runtime, but explodes in CTFE: --- bool isInstanceOf(T, O)(O o) { return (cast(T) o) !is null; } --- CTFE doesn't like !is null (cannot compare [...] at compile time). Moreover, in CTFE a failed cast terminates the interpretation (cannot reinterpret class from [...]

Re: test if object is instance of class at compile time

2011-12-21 Thread Vladimir Panteleev
On Wednesday, 21 December 2011 at 20:15:36 UTC, Elvis Maehren wrote: Is this somehow catchable? I believe that's what __traits(compiles, ...) is for: http://dlang.org/traits.html#compiles

Re: test if object is instance of class at compile time

2011-12-21 Thread Jacob Carlborg
On 2011-12-21 21:15, Elvis Maehren wrote: This works fine at runtime, but explodes in CTFE: --- bool isInstanceOf(T, O)(O o) { return (cast(T) o) !is null; } --- CTFE doesn't like !is null (cannot compare [...] at compile time). Moreover, in CTFE a failed cast terminates the