The Phobos put()

Salih Dincer salihdb at hotmail.com
Wed Mar 29 10:36:52 UTC 2023


Why does my `put` work but the Phobos `put` doesn't work with a 
slice?

> onlineapp.d(11): Error: none of the overloads of template 
> `std.range.primitives.put` are callable using argument types 
> `!()(int[], int[])`
/dlang/dmd/linux/bin64/../../src/phobos/std/range/primitives.d(386):        Candidate is: `put(R, E)(ref R r, E e)`

```d
void main()
{
     import std.range : phobos_put = put;
   
     enum testLen = 4;
     auto a = new int[testLen];
     auto b = new int[testLen];

     auto slice = a[1..$-1];
     slice.phobos_put([2, 3]);
     //a[1..$-1].phobos_put([2, 3]);
     b[1..$-1].put([2, 3]);

     import std.conv : text;
     assert(a == b, text(a));
}

void put(R)(R[] range, R[] source)
{
   assert(source.length <= range.length);
   foreach(element; source)
   {
     range[0] = element;  // range.front()
     range = range[1..$]; // range popFront()
   }
}
```

SDB at 79


More information about the Digitalmars-d-learn mailing list