Range Redesign: Empty Ranges
Atila Neves
atila.neves at gmail.com
Wed Mar 6 12:20:40 UTC 2024
On Monday, 4 March 2024 at 21:29:40 UTC, Jonathan M Davis wrote:
> Okay. A few weeks ago, I made a post about potential design
> decisions when updating the range API in the next version of
> Phobos, and this is a continuation of that, albeit with a
> different set of problems. Specifically:
>
> [...]
I like T.init being empty. I thought I'd found a clever way to
make this work for classes but apparently this crashes, much to
my surprise:
```d
class Class {
bool empty() @safe @nogc pure nothrow scope const {
return this is null;
}
}
Class c;
assert(c.empty);
```
This, although supposedly equivalent, works fine:
```d
class Class {}
bool empty(in Class c) @safe @nogc pure nothow {
return c is null;
}
```
Which might be a way out? I still think the first example should
work.
More information about the Digitalmars-d
mailing list