std.range's put on arrays needs to change

Kostiantyn Tokar tokarkonstantyn at yandex.ua
Sun Jun 26 12:03:21 UTC 2022


Sorry, I misunderstood. For some reason I thought that `put` is 
suggested to append to a slice, like `put` with `appender`. But 
anyway, I still want to ask the question about functions that use 
`put` internally.

On Saturday, 25 June 2022 at 23:44:59 UTC, WebFreak001 wrote:
> I strongly feel that this behavior is very inconsistent and 
> unexpected for most users and should be changed. I think we 
> should deprecate simple arrays/slices on `put` and rename the 
> method for those.
>
> I propose put with slices should be renamed to `putInto`.

To put it into a context, consider the following code:
```
void main() @nogc
{
     import std : iota, copy, save;
     import core.stdc.stdlib : malloc;
     auto n = 5;
     auto buffer = (cast(int*) malloc(n * int.sizeof))[0..n];
     n.iota.copy(buffer.save);
}
```
Currently this code fills the buffer, allocated by `malloc`, with 
the elements of `iota`.

Now, assuming the suggested change is implemented, how do I 
replicate the current behaviour after the deprecation period? 
Iterate over `iota` and call `putInto` directly?


More information about the Digitalmars-d mailing list