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

Joerg Joergonson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 19 08:59:41 PDT 2016


On Sunday, 19 June 2016 at 10:10:54 UTC, Jonathan M Davis wrote:
> 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

Thanks for your 2c... but I think I can handle it. I'm a big boy 
and I wear big boy pants and I'm not afraid of a few little 
scrapes.


If foreach removes all/any of the elements of a container then 
something is broke.




More information about the Digitalmars-d-learn mailing list