The Phobos Put

Salih Dincer salihdb at hotmail.com
Thu Mar 30 18:20:33 UTC 2023


On Thursday, 30 March 2023 at 13:27:33 UTC, Steven Schveighoffer 
wrote:
> But you can do `dig.copy(buf[])` since a dynamic array is.


Apparently, we will not be able to get rid of the necessity of 
using slices. 😀 Neither with "copy" nor with "put"...

```d
import std.algorithm.mutation : copy;
import std.range.primitives : put;

void main()
{
   int[8] buf;// = new int[8];
   auto dig = [1, 2, 3, 4];

   //dig.copy(buf[2..$-2]);/*
   auto slice = buf[2..$-2];
   dig.copy(slice);
   
   assert(buf == [0, 0, 1, 2, 3, 4, 0, 0]);
   buf = 0;
   slice.put(dig);//*/
   assert(buf == [0, 0, 1, 2, 3, 4, 0, 0]);
}
```
SDB at 79



More information about the Digitalmars-d-learn mailing list