Motive behind !empty() with front() instead of Optional front()
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Mar 30 00:51:44 UTC 2021
On 3/24/21 3:23 PM, Per Nordlöw wrote:
> What's the motive behinds D's range design choice of needing
>
> if (!empty)
> {
> // use front or back
> }
>
> instead of having front returning an optional/maybe type with enforced
> pattern matching?
Efficiency. It would be impossible to iterate an array as a range
without copying each and every element thereof.
We investigated a few other possibilities, such as returning a pointer
to the next element or null. But that has problems related to safety and
escaping pointers.
More information about the Digitalmars-d
mailing list