Unmanaged drop in replacemet for [] and length -= 1

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 19 03:10:54 PDT 2016


On Saturday, June 18, 2016 21:55:31 Joerg Joergonson via Digitalmars-d-learn 
wrote:
> I wanted to switch to std.container.Array but it doesn't seem to
> mimic [] for some odd ball reason.

D's dynamic arrays are really quite weird in that they're sort of containers
and sort of not. So, pretty much nothing is ever going to act quite like a
dynamic array. But when dynamic arrays are used as ranges, their semantics
definitely are not that of containers. Having a container which is treated
as a range is just begging for trouble, and I would strongly advise against
attempting it. When it comes to containers, ranges are intended to be a view
into a container, just like an iterator is intended to be a pointer into a
container. Neither ranges are iterators are intended to _be_ containers.
Treating a container as a range is going to get you weird behavior like
foreach removing every element from the container.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list