Question about overloading opSlice(3,4)

nobody nobody at mailinator.com
Fri Aug 18 10:06:17 PDT 2006


Overloading Slicing a[] and a[i .. j]
http://digitalmars.com/d/operatoroverloading.html

Suppse I have the following:

   struct ByteArray // just bytes
   {
     byte[] b;
   }

Now suppose I want to (not want, must) overload opSlice. Now I have to deal with 
things like:

   ByteArray bArr;
   short[]   sArr; // assume it holds data
   int[]     iArr; // assume it holds data

    bArr = sArr[];       // bArr.opSlice()
    bArr = iArr[];       // bArr.opSlice()
    bArr = sArr[0 .. 1]; // bArr.opSlice(0,2)
    bArr = iArr[0 .. 1]; // bArr.opSlice(0,4)

As I understand opSlice bArr should point to data inside either sArr or iArr 
after any of these slices. But bArr is called via opSlice() or opSlice(i,j).
So how does one do that if one gets no information about sArr or iArr?



More information about the Digitalmars-d-learn mailing list