Forward ranges in Phobos v2

Adam D Ruppe destructionator at gmail.com
Tue Nov 2 19:48:38 UTC 2021


On Tuesday, 2 November 2021 at 19:44:02 UTC, H. S. Teoh wrote:
> I find it very useful as well, but according to Andrei, v2 will 
> get rid of class-based ranges, and if those are wanted we 
> should use a struct wrapper instead.

Well, you'd keep the class for the actual wrapper, then the 
struct is just a thin thing on top of that.

interface IInputRange {
    // yada
}

struct InputRange {
    IInputRange c;
}

So you'd wrap it like that. Then for forward range make the copy 
constructor call the clone/save/deepCopy/whatever method on the 
class.

Then the std.algorithm things just take InputRange. A few details 
to work out but it is a simple enough thing to do.



More information about the Digitalmars-d mailing list