On Friday, 24 June 2016 at 18:27:07 UTC, Steven Schveighoffer wrote:
void fun(T)(T obj)
{
static if (!hasMember(T, "gun")) throw new Exception("No gun");
    obj.gun;
}

Call with something that doesn't have a gun member, and even without the reachability warnings (no -w switch), it doesn't compile. However, with an else clause, it would compile.

I might be stepping on a land mine by bringing it up, but isn't this sort of thing what contracts are for?

-Wyatt

Reply via email to