Array Indexing/Slicing Range Checking, Exceptions and @nogc

Nordlöw via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Mar 30 06:49:08 PDT 2016


On Wednesday, 30 March 2016 at 13:38:40 UTC, Adam D. Ruppe wrote:
> Don't use your ptr method. Instead, make it a slice method: 
> `return _store[0 .. _length];`
>
> Now you can just index it internally and let the compiler 
> automatically insert range checks. When you need the pointer, 
> you still have slice.ptr.
>
> So punt the problem to the compiler. This will also ensure you 
> always use it correctly too.

Superb! Thanks.


More information about the Digitalmars-d-learn mailing list