test if object is instance of class at compile time

Elvis Maehren maehlvis at googlemail.com
Thu Dec 22 07:55:04 PST 2011


Timon Gehr wrote:
> On 12/21/2011 09:15 PM, Elvis Maehren wrote:
[...]
>> Moreover, in CTFE a failed cast terminates the interpretation ("cannot
>> reinterpret class from [...] to [...] at compile time").
> 
> I don't think this is filed already. Maybe you want to file a bug report?

ok, did that: http://d.puremagic.com/issues/show_bug.cgi?id=7154

[...]
> use traits(__compiles, {...}), where '...' is the exact code that fails.
> But that is a mere workaround. What you are doing should/will work.

Vladimir Panteleev pointed me to __traits(compiles, ...), too. I think that 
doesn't work out:

Elvis Maehren wrote:
> 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.

Or am I missing something?


More information about the Digitalmars-d-learn mailing list