'unwrap envy' and exceptions

Paul Backus snarwin at gmail.com
Fri Sep 10 16:57:13 UTC 2021


On Friday, 10 September 2021 at 16:10:27 UTC, jfondren wrote:
> In a -release build, over an `int[]`, you get a RangeError from 
> std.range.primitives.front:
>
> ```d
>     assert(a.length, "Attempting to fetch the front of an empty 
> array of " ~ T.stringof);
>     return a[0];
> ```
>
> So the skipped assert() there and the skipped contract 
> programming assert() in minElement/maxElement, all they're 
> really doing is improving the error message. That might be why 
> they're not mentioned.

Either way, if a function has a precondition that the caller 
needs to satisfy, it should be documented.

https://github.com/dlang/phobos/pull/8238


More information about the Digitalmars-d mailing list