How to check if something can be null

user1234 user1234 at 12.de
Fri Jul 1 15:31:36 UTC 2022


On Friday, 1 July 2022 at 13:53:28 UTC, Antonio wrote:
> On Friday, 1 July 2022 at 13:48:25 UTC, Antonio wrote:
>> -Why?
>
> I realized Json is an struct (not an object)... and I supose, 
> it is managing null asignation manually (as a way to build 
> Json(null)).
>
>> -Whats the correct whay to test if something can be null?
>
> That's my question :-p

Something like this does the job:

```d
enum canBeNull(T) = is(typeof({T t; t = null;}));
static assert(canBeNull!(Object));
static assert(!canBeNull!(int));
```

and that should handle opAssign and opCmp overloads.


More information about the Digitalmars-d-learn mailing list