Proof of concept for v2 - NO duplication, NO `static if` hell, NO difficulty with interoperability

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Nov 1 14:29:20 UTC 2021


On Mon, Nov 01, 2021 at 02:09:44PM +0000, Ogi via Digitalmars-d wrote:
> On Sunday, 31 October 2021 at 01:59:38 UTC, Andrei Alexandrescu wrote:
> > https://github.com/dlang/phobos/pull/8309
> > 
> > Destroy!
> 
> Good stuff.
> 
> Notably absent are `std.range.interfaces`. What are we going to do
> about them?

I think Andrei has indicated in the past that we want to get rid of it.

But IMO, practically speaking, sometimes object wrappers for ranges are
necessary. For example, if you need to alternate between two
incompatible UFCS chains based on a runtime condition (so you can't use
std.range.choose), or you need to return one UFCS chain or another from
a function based on a runtime condition:

	// This will not compile because of divergent return types.
	auto runtimeChoice(R)(R srcRange, bool condition) {
		if (condition)
			return srcRange.filter!someCriterion;
		else
			return srcRange.map!(x => someMap(x))
					.filter!someCriterion;
	}

	// So we need to do this instead:
	auto runtimeChoice(R)(R srcRange, bool condition) {
		if (condition)
			return inputRangeObject(srcRange.filter!someCriterion);
		else
			return inputRangeObject(srcRange.map!(x => someMap(x))
						.filter!someCriterion);
	}

Phobos v2 better have a way to deal with this.  Either that, or keep the
current definition of forward ranges until v3, to avoid too massive a
change.


T

-- 
There are two ways to write error-free programs; only the third one works.


More information about the Digitalmars-d mailing list