built-in array ptrEnd
monarch_dodra
monarchdodra at gmail.com
Mon Sep 17 09:34:48 PDT 2012
I love D's concept of arrays (fat pointers).
However, one thing I've found it lacks is a (convenient) way to
get the end ptr.
Phobos (and druntime) are riddled with "arr.ptr + arr.length". It
is ugly and inconvenient, and makes something that should be easy
to understand that much harder.
Then I thought: "std.array" defines all the functions required to
enhance arrays. Why not just add a "ptrEnd" in there? So I did.
The rational is that now, we can write:
bool isDisjoint = a.ptrEnd <= b.ptr || b.ptrEnd <= a.ptr;
More elegant than:
bool isDisjoint = a.ptr + a.length <= b.ptr ||
b.ptr + b.length <= a.ptr;
Nothing revolutionary, but it *is* easier on the fingers when
typing :D . Also, it *does* make a change in some bigger and more
complicated cases.
Anyways, pull request:
https://github.com/D-Programming-Language/phobos/pull/798
I wanted to have some feedback, as this is introducing something
new (as opposed to fixing something existing).
IMO, this should really be built-in, in particular, since, in my
understanding, an array is internally represented by the ptr and
ptrEnd pair anyways. If the compiler has access to it, it might
as well communicate it (rather than us re-calculating it...)
More information about the Digitalmars-d
mailing list