On Thursday, 20 March 2014 at 21:32:08 UTC, dnspies wrote:
Sorry, I don't understand. When I cast something to the wrong type, I should just get a null reference, shouldn't I? It shouldn't throw an error.
If the compiler can statically determine that the cast is invalid you get an error instead. You can use something like 'static if(is(T : Foo))' to test at compile-time if T is implicitly convertible to Foo (I'm not certain the exact semantics) or 'static if(is(typeof(cast(Foo)T.init)))'.
There's probably better ways to do it, and I recommend asking on D.learn to figure out how to do what you're looking for.
