assert or throw in range members?
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Aug 5 03:39:33 PDT 2016
On 08/05/2016 12:25 PM, 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?
It's an error in the program when front/back is called on an empty
range. Every program must be written so that this cannot ever happen.
assert is for catching programming errors. So assert is ok here. Not
checking at all would be ok, too, but assert is a bit nicer to the user
of the range, of course.
More information about the Digitalmars-d-learn
mailing list