On Saturday, 8 December 2018 at 03:51:02 UTC, Adam D. Ruppe wrote:
On Saturday, 8 December 2018 at 03:48:10 UTC, Murilo wrote:
Try passing `ps[]` to the function instead of plain `ps` and see what happens.

How do I transform an array into a range?

With the slicing operator, [].

That's amazing, this should be one thing that should appear in every tutorial just right at the start! I was looking hours for a way to generate an "iterator" (a range) from a fixed-size array which doesn't copy the elements (unless elements are deleted/added).

But my issue now is, I have strided arrays (or just any Result range) and I want to use the slicing operator `[]` with that range to copy it into a fixed-size array or apply element-wise operations on it. How can I do that?

This example will not compile:

```
        auto starts = arr[0..$].stride(2);
        auto ends = arr[1..$].stride(2);
        randomNumbers[] = ends[] - starts[];
```

Because `[]` is not defined for the Result range. Is there a standard wrapper function which wraps an elementwise `[]` operator implementation around a range?

Reply via email to