Slicing upward

rikki cattermole rikki at cattermole.co.nz
Sat Sep 14 11:39:21 UTC 2019


On 14/09/2019 11:34 PM, Brett wrote:
> I have an algorithm that is most efficiently implement by taking an 
> array and slicing it upward, meaning removing the leading elements.
> 
> Because the algorithm is complex(deterministic but chaotic) and deals 
> with multiple arrays it is difficult to efficiently use slicing.
> 
> Is there some easy way to take an array and slice it in a way that as 
> the array grows any slices will "shift".
> 
> Essentially it is sort of reversing how normal slices are represented
> 
> [2,4,1,64]
> slice last 2, [1,64]

That part is easy.

```
import std.stdio;

void main() {
	int[] array = [2,4,1,64];
	array[$-2 .. $].writeln;
}
```


More information about the Digitalmars-d-learn mailing list