called copy constructor in foreach with ref on Range

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Jun 23 02:28:49 UTC 2020


On Monday, June 22, 2020 3:38:02 PM MDT Paul Backus via Digitalmars-d-learn 
wrote:
> On Monday, 22 June 2020 at 21:33:08 UTC, H. S. Teoh wrote:
> > Jonathan is coming from the POV of generic code.  The problem
> > with move leaving the original range in its .init state isn't
> > so much that it will crash or anything (even though as you said
> > that does indicate a flaw in the range's implementation), but
> > that the semantics of generic code changes in subtle ways. For
> > example:
> >
> > [...]
>
> Seems to me like adding some unit tests with non-copyable input
> ranges to Phobos could expose a number of latent bugs.

At this point, non-copyable ranges really aren't a thing. foreach does not
support them and neither does Phobos. isInputRange doesn't actually reject
them, but they don't really work in practice, and it's unlikely that you're
going to find much in Phobos that happens to work with them. isForwardRange
does outright reject them though.

- Jonathan M Davis





More information about the Digitalmars-d-learn mailing list