How is chunkBy supposed to behave on copy

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Mar 20 23:01:28 UTC 2020


On Fri, Mar 20, 2020 at 10:15:18PM +0000, Ben Jones via Digitalmars-d wrote:
> On Friday, 20 March 2020 at 22:11:49 UTC, H. S. Teoh wrote:
[...]
> > Yes, that's right.  Actually, for by-value ranges the act of passing
> > them as an argument to a range function in the first place already
> > copies them.  The catch is really that once this happens, the caller
> > or whoever retains the original copy should no longer assume that
> > the range remains in the same place as before.  For some ranges this
> > is true, but for other ranges this assumption is invalid, and will
> > lead to incorrect results.
[...]
> So range "copy" is really what a C++ person would call range "move" ?
> It might be a copy, or it might invalidate the original, depending on
> the type?

The way it's currently implemented, yes, pretty much.  Unless you're in
control of the exact range type, you should always assume the worst and
not rely on the state of the original range after passing it to a range
function.  If you need to retain the original state, use .save.


T

-- 
You are only young once, but you can stay immature indefinitely. -- azephrahel


More information about the Digitalmars-d mailing list