Understanding range.dropBackOne
Adam Ruppe
destructionator at gmail.com
Tue Sep 28 23:12:14 UTC 2021
On Tuesday, 28 September 2021 at 22:56:17 UTC, Tim wrote:
> I'm doing the following:
>
> int[25] window = 0;
Note that this array has a fixed size.
> window = someInteger ~ window[].dropBackOne;
Here the window[] takes a variable-length slice of it. Turning it
from int[25] into plain int[]. Then you can drop one since it is
variable length. Then appending again ok cuz it is variable. Then
the window assign just copies it out of the newly allocated
variable back into the static length array.
> window = someInteger ~ window.dropBackOne;
But over here you are trying to use the static array directly
which again has fixed length, so it is impossible to cut an item
off it or add another to it.
> What does the `[]` do exactly? Is an array not a bidirectional
> range?
It takes a slice of the static array - fetching the pointer and
length into runtime variables.
More information about the Digitalmars-d-learn
mailing list