std.range's put on arrays needs to change

H. S. Teoh hsteoh at qfbox.info
Sun Jun 26 05:10:50 UTC 2022


On Sun, Jun 26, 2022 at 04:21:46AM +0000, Paul Backus via Digitalmars-d wrote:
> 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`.
> 
> I agree that `put` on arrays does not do what you usually want it to
> do, but I do not agree that it is inconsistent. It is exactly the same
> behavior you would get if you used the input range interface and wrote
> `arr.front = 2; arr.popFront;`.

Yeah, it's consistent where calling put multiple times writes to
consecutive locations in the original array.


[...]
> IMO `put` should be changed in `std.v2` to either throw an exception
> or return `false` when attempting to insert an element into a full
> output range.

Why the needlessly complex workaround? Just introduce a .full method,
the natural analogue of .empty for output ranges.


T

-- 
Public parking: euphemism for paid parking. -- Flora


More information about the Digitalmars-d mailing list