assert or throw in range members?

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 5 04:15:36 PDT 2016


On Friday, 5 August 2016 at 10:25:42 UTC, Nordlöw wrote:
> Should range members front() and back() assert() or throw() on 
> emptyness?
>
> If it should assert() doesn't that lead to unsafer code in 
> release mode?
>
> What's the consensus here?

if you can and it is not costly, do `assert(false, "BOOM!");` 
there. as it is UB anyway, you can make programmer's life little 
easier. ;-)

also, `assert()` doesn't break @nogc, if somebody cares.


More information about the Digitalmars-d-learn mailing list