Range Redesign: Empty Ranges
Ogi
ogion.art at gmail.com
Wed Mar 6 13:09:52 UTC 2024
On Wednesday, 6 March 2024 at 12:20:40 UTC, Atila Neves wrote:
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);
> ```
I’m surprised that the equivalent C++ code *doesn’t* crash (at
least on my machine):
```
Class* c = nullptr;
assert(c->empty());
That’s still UB though.
More information about the Digitalmars-d
mailing list