How do you safely deal with range.front?
aliak
something at something.com
Mon Jan 1 18:38:36 UTC 2018
On Monday, 1 January 2018 at 02:18:36 UTC, Jonathan M Davis wrote:
> Except that the reason for arrays throwing RangeErrors when you
> try and index them out-of-bounds is to avoid memory safety
> issues, which is not necessarily the case at all when you're
> talking about ranges. Having ranges in general be checking
> empty in front, popFront, back, etc. would add unnecessary
> overhead - especially when you consider that ranges often wrap
> other ranges. You'd be layering on check after check when the
> calling code is already supposed to be checking empty when
> necessary to make sure that the range isn't empty. You'd even
> be layering checks on top of the checks that arrays already do,
> since many ranges are ultimately wrapped around a dynamic array
> at their core.
>
> [...]
Makes sense. Especially after pointing out that ranges are mostly
arrays at the end. Thanks!
More information about the Digitalmars-d-learn
mailing list