container stuff

Steven Schveighoffer schveiguy at yahoo.com
Wed May 26 14:47:02 PDT 2010


Andrei Alexandrescu Wrote:


> > Finally, opSlice(begin, end) is not there.  Was this intentional or
> > overlooked?
> 
> I'm still mulling over that. As was discussed in this group, $ is easy 
> to detect statically but 0 is not. Some containers don't like nonzero 
> beginning anchors, and I wouldn't want to make that a runtime test.

It would most likely not violate an O(lg(n)) requirement to check that the beginning anchor was indeed the beginning.  In fact, it would be about as much work as opSlice(), since you have to find that beginning anchor anyways...

> If 
> Walter won't make a language change, I'd have to define begin() as an 
> anchor, and before you know it, cursors are in :o).

I'm all for a language change and cursors ;)

> b) associative arrays can define c[a .. b] for a, b key types. It's 
> nontrivial but it can be done.

I decided for dcollections that this only makes sense on sorted maps.  It is a little questionable to check in runtime that b > a on something like a hash map, but besides that point, it's non deterministic.  Slicing with keys on c[a..b] might work before a rehash, and not work after one.  This latter point is what made me disallow it.

> 
> c) sentinel-terminated arrays (e.g. C stringz) can only define c[a .. $] 
> for an integral a.

I really hope we are not considering null-terminated strings when deciding container functions...

> e) Any other cases?

On a sorted AA, slicing using any two keys are possible (as long as the keys exist in the AA).

-Steve


More information about the Digitalmars-d mailing list