Motive behind !empty() with front() instead of Optional front()
Nick Treleaven
nick at geany.org
Fri Mar 26 19:20:51 UTC 2021
On Friday, 26 March 2021 at 15:53:39 UTC, Steven Schveighoffer
wrote:
> Notice that it's an assert, which means it can be removed in
> correctly-written programs. If you return an Optional,
> emptiness MUST be checked on every access to an element, even
> when you know (or have proven) it's not empty.
An optional would have an `unwrap` method for this purpose, which
also only asserts it is not empty and returns a value.
More information about the Digitalmars-d
mailing list