[Issue 22293] New: Nullable should define opCast!bool
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Sep 9 20:33:31 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22293
Issue ID: 22293
Summary: Nullable should define opCast!bool
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: schveiguy at gmail.com
Now that Nullable.get is not alias-this, it would make sense to make
if(someNullable) work, instead of always having to do if(!someNullable.isNull),
which is harder to read (the ! appears at the beginning, of a possibly long
expression chain, plus its a negation which is always harder).
A bonus is that if(auto x = expressionReturningNullable) will work as well.
To do this, we just have to add opCast(T: bool) { return !isNull; } to the
type.
Not sure on the situation with Nullable with a null value, since that still has
the alias-this.
--
More information about the Digitalmars-d-bugs
mailing list