assert or throw in range members?
Cauterite via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Aug 5 03:34:44 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?
I'm pretty sure it's assert() here. The contract is that the
caller is responsible for checking emptiness beforehand, and the
whole of Phobos is coded around that contract.
I think.
> If it should assert() doesn't that lead to unsafer code in
> release mode?
That's the point of release mode. Omitting superfluous checks
based on the assumption that your code is correct (e.g.
assumption that the emptiness contract is respected).
More information about the Digitalmars-d-learn
mailing list