Bug 15798 – std.algorithm.mutation.copy takes target by value

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-03-15T00:10:49Z
Last change time
2024-12-01T16:26:20Z
Assigned to
Eduard Staniloiu
Creator
Adam D. Ruppe
Moved to GitHub: phobos#10167 →

Comments

Comment #0 by destructionator — 2016-03-15T00:10:49Z
See: http://stackoverflow.com/a/36000424/1457000 Try copying into a MD5. It is recognized as an output range and triggers the overload that just calls put(dst, src), but since the target was passed by value, the change is not seen on the outside!
Comment #1 by astrothayne — 2016-03-21T06:40:47Z
Simply changing the Target to a ref wouldn't be backward compatible, because then it wouldn't be possible to use an rvalue as a target, which is useful for copying to an array slice, or using a range that wraps another output range, such as retro. Also, std.range.put _does_ take a reference, and can be used to copy a range. Alternatively, copy returns the state of the output range after copying, so in the MD5 example you could use `s.copy(d2).finish().toHexString` to get the correct MD5 sum.
Comment #2 by jack — 2018-01-16T17:53:14Z
To be honest, the behavior of copy really only makes sense for array targets. It doesn't make any sense to return the "remainder" of a generic output range. copying to non-arrays should be deprecated
Comment #3 by jack — 2018-01-17T01:53:23Z
Comment #4 by robert.schadek — 2024-12-01T16:26:20Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10167 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB