Range Redesign: Empty Ranges

Meta jared771 at gmail.com
Wed Mar 6 17:51:11 UTC 2024


On Wednesday, 6 March 2024 at 17:32:17 UTC, H. S. Teoh wrote:
> Every time this topic comes up, class-based ranges become the 
> whipping boy of range design woes.  Actually, they serve an 
> extremely important role: type erasure, which is critical when 
> you have code like this:
> ...etc.

This would be a complete non-issue if we had language-level 
sumtypes:

```
	sumtype { R, S } myRangeFunc(R,S)(R range1, S range2) {
		if (runtimeDecision()) {
			return range1;
		} else {
			return range2;
		}
	}
```

std.sumtype can also do this, the ergonomics just aren't as nice.


More information about the Digitalmars-d mailing list