How is chunkBy supposed to behave on copy

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Mar 23 18:15:19 UTC 2020


On Sunday, March 22, 2020 9:43:45 AM MDT H. S. Teoh via Digitalmars-d wrote:
> On Fri, Mar 20, 2020 at 05:50:26PM -0600, Jonathan M Davis via
> Digitalmars-d wrote: [...]
>
> > And exactly what should happen with basic input ranges is not clear,
> > because while ideally, you'd just require that they have full-on
> > reference semantics, that tends to mean that you're forcing them to be
> > allocated on the heap, which isn't really the sort of thing that we
> > want to force if we can avoid it.
>
> [...]
>
> You could just have input ranges be a struct with the copy ctor
> @disable'd, perhaps?

A range that can't be copied is useless. It won't even work with foreach,
because anything you iterate over with foreach is copied when it's passed to
foreach. And of course, idiomatic range code passes ranges all over the
place, resulting in a lot of copying. And to wrap a range in another range
(which is required for most range-based algorithms), you have to copy it.
IMHO, it would make far more sense to just use opApply than to try to make a
range non-copyable.

- Jonathan M Davis





More information about the Digitalmars-d mailing list