How to check if value is null, today?
jfondren
julian.fondren at gmail.com
Thu Oct 14 12:43:36 UTC 2021
On Thursday, 14 October 2021 at 11:58:29 UTC, tastyminerals wrote:
> Here is an example code that doesn't work with the new compiler
> anymore:
>
> ```
> if (someValue.isNull)
> ```
>
> Attempting to run the above throws:
> ```
> Error: incompatible types for `(0) : (someValue)`: `int` and
> `Nullable!int`
> ```
>
Do you have a complete example? Because this runs without error:
```d
import std.typecons : nullable, Nullable;
import std.stdio : writeln;
void main() {
auto a = nullable(1);
auto b = Nullable!int.init;
if (!a.isNull)
writeln(a.get);
if (b.isNull)
writeln("b is null");
}
```
More information about the Digitalmars-d-learn
mailing list