Understanding range.dropBackOne

Tim tim.oliver at tutanota.com
Tue Sep 28 23:13:54 UTC 2021


On Tuesday, 28 September 2021 at 23:12:14 UTC, Adam Ruppe wrote:
> On Tuesday, 28 September 2021 at 22:56:17 UTC, Tim wrote:
>> [...]
>
> Note that this array has a fixed size.
>
>> [...]
>
> 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.
>
>> [...]
>
> 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.
>
>> [...]
>
> It takes a slice of the static array - fetching the pointer and 
> length into runtime variables.

Perfect answer. Thanks for clearing that all up mate


More information about the Digitalmars-d-learn mailing list