Array Slice Ranges

Nikita Kalaganov nkalaganov at icl.kazan.ru
Thu Nov 9 08:17:49 PST 2006


Hmm, as far as I understand, the non-inclusive slice avoids massive '+1'
appearings in source.

For example (slice five elements]:

uint size = 5;
data[head..head + size] //is better than data[head..head + size + 1] for inclusive
slice

But, there are better syntax available:

[2..5] means 2,3,4,5 (inclusive slice)
[2..:5] means 'take five elements, first is at index 2', to avoid '+1' problem

So, example becomes:

uint size = 5;
data[head..:size] //good, isn't it ?

---
CON: making '..' slice inclusive breaks a lot of code :(




More information about the Digitalmars-d mailing list