I'm working on a support-it-all Array implementation (with optional sortedness) at

https://github.com/nordlow/justd/blob/master/packedarray.d

that has a very flexible memory allocation model via either GC.malloc or via privately imported malloc, realloc and free. This in order to provide pure @trusted access in all cases except slicing and `auto ref opIndex`.

I'm however uncertain about how to implement error handling of bounds checking and how these interact with `@nogc`. My main goal is to match semantics of builtin D arrays and slices. If so should we implement bounds checking as either

opIndex(size_t index) nothrow @nogc
{
    assert(index < length, "Index out of bounds");
}

or via

opIndex(size_t index) // cannot be nothrow @nogc
{
if (index >= length) { throw new RangeError("Index out of bounds"); }
}

?

What's the preferred policy here?

Reply via email to