Forward ranges in Phobos v2

Dukc ajieskola at gmail.com
Tue Nov 2 12:11:24 UTC 2021


On Tuesday, 2 November 2021 at 02:45:11 UTC, Andrei Alexandrescu 
wrote:
>
> Exactly. No need to support class ranges - simple wrappers can 
> do everything class-like indirection does. Thanks.

Trying to write up a plan based on that one, so you can correct 
and/or spot weaknesses

- stuff in `std.v2.range.interfaces` and 
`std.v2.concurrency.Generator` will continue to be ranges from 
Phobos v1 viewpoint but not from Phobos v2 viewpoint.

- We add a function, let's say `std.range.valueRange`, in both 
versions, that will convert any v1 forward range to a value range 
that works in both versions.

- We also add some other function, or perhaps a flag to 
aforementioned one, that can convert any v1 input ranges to v2 
input range. `valueRange` as default must not accept non-forward 
ranges, because then it cannot guarantee that the result will be 
a value range.

- We need some way to prevent Phobos v2 using v1 reference 
forward ranges accidently. Making v2 `isInputRange` to be an 
automatic negative for classes can suffice for now.

- Phobos v2 ranges should still continue to provide the `save` 
method so they can be passed to v1 ranges. We also might provide 
an `assumeValueRange` function that will add the `save` method on 
top of any existing input range, assuming value semantics and 
making it a forward range from v1 perspective.


More information about the Digitalmars-d mailing list