proper range usage

Alex via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 3 15:08:23 PST 2015


On Tuesday, 3 November 2015 at 22:36:21 UTC, Ali Çehreli wrote:

> That's fine. D's slices do that all the time: arr[0..3] and 
> arr[3..$] seem to share index 3 but it is not the case: The 
> first slice does not use it but the second one does.

Ok... great! This is what I worried about...

> Aside: If 'begin' and 'end' are indexes into an actual array 
> (of Ms? I forgot), perhaps you can keep slices instead:
>
> struct P
> {
>      int id;
>      alias id this;
>      M[] ms;    // <--
> }
>
> It would be almost as efficient but larger: Altough you use two 
> ints (total 8 bytes), a slice is 16 bytes on a 64-bit system: a 
> pointer and a size_t.
>
Thats cool! Thank you very much!




More information about the Digitalmars-d-learn mailing list