On Thursday, 30 June 2016 at 11:06:56 UTC, Steven Schveighoffer wrote:
On 6/29/16 11:40 AM, Wyatt wrote:
I might be stepping on a land mine by bringing it up, but isn't this
sort of thing what contracts are for?

No landmines here, but no, that isn't what contracts are for. Perhaps you mean constraints?

Sure. IME, contracts are generally written as a series of constraints anyway.

A constraint will prevent compilation vs. allowing compilation but emitting a failure at runtime. I agree this is a better mechanism, or just plain allow the compiler to make a proper error when you call gun.

Isn't doing it at compile time as simple as using e.g. static assert(hasMember(T, "gun"))? I do feel like I've been in situations before where this kind of thing was better as a recoverable runtime exception, but I can't remember where.

The more I think about this, though, the less the proposal makes sense for the problem. Like, I get that it might be a tiny bit annoying, but I see a lot more potential for human error; pulling a "goto FAIL" and running code that shouldn't be or such.

-Wyatt

Reply via email to