KennyTM~ wrote:
On May 16, 10 02:01, Walter Bright wrote:
Simen kjaeraas wrote:
Walter Bright <[email protected]> wrote:

Simen kjaeraas wrote:
Walter Bright <[email protected]> wrote:

KennyTM~ wrote:
Why a map type (sorted associative array)'s key must start at zero?

You can special case the [0..$], or simply use [] to represent the
entire range.
Of course, but assume you want the first 15 elements, what do you do?


For a map, does the first 15 elements even make any sense? There is
no order in a map.

std::map is ordered. Other data structures might make more sense.

A weird example would be a trie - slice all from the start
to ['f','o','o'], for instance.


If it's ordered, then why doesn't [0..15] make sense to get the first 15
elements?

auto a = new OrderedDict!(int, string);
a[-3] = "negative three";
a[-1] = "negative one";
a[0] = "zero";
a[3] = "three";
a[4] = "four";
assert(a[0] == "zero");
return a[0..4]; // which slice should it return?

Good question.

Reply via email to