On Thu, 17 Mar 2011 11:49:25 -0400, bearophile <bearophileh...@lycos.com>
wrote:
Steven Schveighoffer:
All the other points, I disagree with bearophile, enforce is not assert
and should not be nothrow.
I have never said this. I am aware that enforce can't be nothrow, and I
agree that in some situations you want to raise an exception instead of
using asserts. One of the things I have said (maybe wrongly) are:
You have to add that such "if (!condition) throw new Exception(args)"
idiom is common in Phobos because Phobos is present only in release
mode. If the zip distribution of DMD contains two Phobos and dmd
becomes able to use the right one according to the compilation
switches, then I think that "if (!condition) throw new Exception(args)"
will become more rare, and the enforce() too will be less commonly
needed.<
I was going off of this statement:
"It doesn't allow functions to be nothrow. This is a fault, because D has
Contract Programming, that is meant to be usable for nothrow functions
too. D Contracts with asserts are the right tool."
Sorry if I misunderstood.
But enforce is a simple factoring of the if(!condition) throw
Exception(msg) into an expression. It is meant to throw an exception and
meant to be used in release mode.
The only problem I see with it is the inline-killing.
-Steve