Proposed Changes to the Range API for Phobos v3

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Fri May 17 04:48:26 UTC 2024


On 17/05/2024 4:22 AM, Jonathan M Davis wrote:
> It seems like you're proposing that we start requiring wrapper structs for
> some of the most common kinds of ranges, whereas my proposal would be
> requiring wrapper structs only for rare ranges - ones which are already
> typically generated using helper functions.

Required, yes, automatic yes.

The language could help here, not a pleasant proposal but it would be 
do-able to have the language auto-wrap into a boxed type. Given ranges 
are first class in D, it'll be worth it.

```d
import core.attributes : autobox;

struct Map(@autobox T) {
	this(@autobox T val);
}
```

```d
module core.boxing.slice;

struct BoxedSlice(T) {
	T[] slice;
	alias slice this;

	bool empty() {
		return slice.length == 0;
	}
}
```

The reason I am suggesting this is we clearly don't like the solutions 
being proposed for the range functions for slices. So lets change it to 
a problem we do like and can solve.


More information about the Digitalmars-d mailing list