try/catch idiom in std.datetime

Walter Bright newshound2 at digitalmars.com
Mon Nov 18 12:47:32 PST 2013


On 11/18/2013 2:16 AM, Daniel Murphy wrote:
> Yeah.  On the other hand, if we decide assert(0) means 'assume unreachable'
> we can optimize out the try-catch in release mode, among other things.
>
> try { s } catch { assert(0); } -> s
> if (e) assert(0); else s; -> e; s;

I seriously object to this, as assert(0) is there for when you really do want an 
assert in release builds.

I.e.:

     assert(!e);         // removed in release builds
     if (e) assert(0);   // stays in release builds

It's a valid D idiom, not a bug or oversight.



More information about the Digitalmars-d mailing list