On 05/26/2010 12:40 AM, Jerry Quinn wrote:
softXXX might be better named safeXXX or stableXXX. The names might
be more suggestive of preserving iteration.
Done. "stable". Thanks.
The doc isn't quite clear whether make is a member function or
standalone. I assume it's standalone, but that's worth firming up.
make is standalone, the indentation should give that away.
I don't like insertInstead, can we make it replace?
replace was the original name. insertInstead is consistent with
the other two, so we have (softI|i)nsert[Before|After|Instead].
I second the request for the name "replace". Despite the
consistency, I think replace is clear to programmers as well as being
more familiar and comfortable. Also, the operation really isn't
"insert instead", it's "delete then insert instead". So there is
lack of symmetry because it removes elements while the other does
not.
Good point. I inserted "replace" instead of "insertInstead" (and just
inserted a pun, too).
Another issue I see is that opIndex and its brethren takes KeyType,
but for something like vector, this should be size_t.. I don't think
you want ElementType to be tuple!(size_t, ElementType) in this case.
Arrays don't define KeyType, yet they define opIndex. That doesn't go
against the spec. That being said, I'd like to see a bit more
unification between arrays and associative arrays.
Related to this, do you intend removal of a single element to use
remove(range) or removeKey?
I think remove(range.take(1)) should remove one element. I'm also
thinking of simplifying matters by defining remove(range, k) where k is
an "up to" number.
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. 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).
To recap:
a) arrays (but not associative arrays) can define c[a .. b] for
integrals a and b.
b) associative arrays can define c[a .. b] for a, b key types. It's
nontrivial but it can be done.
c) sentinel-terminated arrays (e.g. C stringz) can only define c[a .. $]
for an integral a.
d) lists can, with ho and hum, define c[0 .. a] for an integral a. The
ho and hum comes from the fact that the range thus obtained is not a
"proper" Range type, it's a Take!Range.
e) Any other cases?
Andrei