opIndex negative index?

IGotD- nise at nise.com
Thu Jan 21 14:25:41 UTC 2021


On Thursday, 21 January 2021 at 14:00:28 UTC, cerjones wrote:
> I have an iterator that steps along a 2D vector path command by 
> command and uses opIndex to give access to the points for the 
> current command. The issue is that there's a shared point 
> between commands, so when the iterator is on a given command, 
> it also needs to also allow access to the end point of the 
> previous command. Currently the iterator juggles the indexes so 
> that for a cubic you use 0,1,2,3, and 0 gives the previous end 
> point. But it would simplify a few things if [-1] was for 
> accessing the previous end point, so a cubic would allow 
> indexes -1,0,1,2.
>
> I'm a bit unsure if this is reasonable or not.
>
> Thoughts?

Not possible, indexes are of type size_t which is unsigned. If 
you want negative indexes you need to wrap arrays in your own 
implementation and offset 0 so that negative indexes can be used.


More information about the Digitalmars-d-learn mailing list